use crate::device::WgpuDevice;
use crate::error::Result;
pub const WGSL_TORSION_ANGLES_DF64: &str =
include_str!("../shaders/folding/torsion_angles_df64.wgsl");
pub const WGSL_DISTANCE_MATRIX_DF64: &str =
include_str!("../shaders/folding/distance_matrix_df64.wgsl");
pub const WGSL_RMSD_DF64: &str = include_str!("../shaders/folding/rmsd_df64.wgsl");
pub const WGSL_CONTACT_MAP_DF64: &str = include_str!("../shaders/folding/contact_map_df64.wgsl");
pub const WGSL_LENNARD_JONES_DF64: &str =
include_str!("../shaders/folding/lennard_jones_df64.wgsl");
pub const WGSL_COULOMB_ELECTROSTATIC_DF64: &str =
include_str!("../shaders/folding/coulomb_electrostatic_df64.wgsl");
pub const WGSL_HYDROGEN_BOND_DF64: &str =
include_str!("../shaders/folding/hydrogen_bond_df64.wgsl");
pub const WGSL_SOLVATION_ENERGY_DF64: &str =
include_str!("../shaders/folding/solvation_energy_df64.wgsl");
pub const WGSL_GRADIENT_DESCENT_DF64: &str =
include_str!("../shaders/folding/gradient_descent_df64.wgsl");
pub const WGSL_SIMULATED_ANNEALING_DF64: &str =
include_str!("../shaders/folding/simulated_annealing_df64.wgsl");
pub const WGSL_BACKBONE_RESTRAINTS_DF64: &str =
include_str!("../shaders/folding/backbone_restraints_df64.wgsl");
pub const WGSL_SIDE_CHAIN_PACKING_DF64: &str =
include_str!("../shaders/folding/side_chain_packing_df64.wgsl");
pub const WGSL_MSA_ATTENTION_DF64: &str =
include_str!("../shaders/folding/msa_attention_df64.wgsl");
pub const WGSL_PAIR_REPRESENTATION_DF64: &str =
include_str!("../shaders/folding/pair_representation_df64.wgsl");
pub const WGSL_STRUCTURE_MODULE_DF64: &str =
include_str!("../shaders/folding/structure_module_df64.wgsl");
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FoldingOp {
TorsionAngles,
DistanceMatrix,
Rmsd,
ContactMap,
LennardJones,
CoulombElectrostatic,
HydrogenBond,
SolvationEnergy,
GradientDescent,
SimulatedAnnealing,
BackboneRestraints,
SideChainPacking,
MsaAttention,
PairRepresentation,
StructureModule,
}
impl FoldingOp {
#[must_use]
pub fn source(&self) -> &'static str {
match self {
Self::TorsionAngles => WGSL_TORSION_ANGLES_DF64,
Self::DistanceMatrix => WGSL_DISTANCE_MATRIX_DF64,
Self::Rmsd => WGSL_RMSD_DF64,
Self::ContactMap => WGSL_CONTACT_MAP_DF64,
Self::LennardJones => WGSL_LENNARD_JONES_DF64,
Self::CoulombElectrostatic => WGSL_COULOMB_ELECTROSTATIC_DF64,
Self::HydrogenBond => WGSL_HYDROGEN_BOND_DF64,
Self::SolvationEnergy => WGSL_SOLVATION_ENERGY_DF64,
Self::GradientDescent => WGSL_GRADIENT_DESCENT_DF64,
Self::SimulatedAnnealing => WGSL_SIMULATED_ANNEALING_DF64,
Self::BackboneRestraints => WGSL_BACKBONE_RESTRAINTS_DF64,
Self::SideChainPacking => WGSL_SIDE_CHAIN_PACKING_DF64,
Self::MsaAttention => WGSL_MSA_ATTENTION_DF64,
Self::PairRepresentation => WGSL_PAIR_REPRESENTATION_DF64,
Self::StructureModule => WGSL_STRUCTURE_MODULE_DF64,
}
}
#[must_use]
pub fn label(&self) -> &'static str {
match self {
Self::TorsionAngles => "torsion_angles_df64",
Self::DistanceMatrix => "distance_matrix_df64",
Self::Rmsd => "rmsd_df64",
Self::ContactMap => "contact_map_df64",
Self::LennardJones => "lennard_jones_df64",
Self::CoulombElectrostatic => "coulomb_electrostatic_df64",
Self::HydrogenBond => "hydrogen_bond_df64",
Self::SolvationEnergy => "solvation_energy_df64",
Self::GradientDescent => "gradient_descent_df64",
Self::SimulatedAnnealing => "simulated_annealing_df64",
Self::BackboneRestraints => "backbone_restraints_df64",
Self::SideChainPacking => "side_chain_packing_df64",
Self::MsaAttention => "msa_attention_df64",
Self::PairRepresentation => "pair_representation_df64",
Self::StructureModule => "structure_module_df64",
}
}
}
pub fn compile_folding_shader(device: &WgpuDevice, op: FoldingOp) -> Result<wgpu::ShaderModule> {
let source = op.source();
let label = op.label();
Ok(device.compile_shader_df64(source, Some(label)))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_folding_shaders_compile() {
let device = crate::device::test_pool::get_test_device_sync();
let ops = [
FoldingOp::TorsionAngles,
FoldingOp::DistanceMatrix,
FoldingOp::Rmsd,
FoldingOp::ContactMap,
FoldingOp::LennardJones,
FoldingOp::CoulombElectrostatic,
FoldingOp::HydrogenBond,
FoldingOp::SolvationEnergy,
FoldingOp::GradientDescent,
FoldingOp::SimulatedAnnealing,
FoldingOp::BackboneRestraints,
FoldingOp::SideChainPacking,
FoldingOp::MsaAttention,
FoldingOp::PairRepresentation,
FoldingOp::StructureModule,
];
for op in ops {
let result = compile_folding_shader(&device, op);
assert!(result.is_ok(), "{} shader failed to compile", op.label());
}
}
}