NewTorsionalDiffusion is a class for simulating the torsional diffusion of a protein model. It inherits from the tasks.Task and core.Configurable classes and uses these to setup and control the diffusion simulation. Attributes: eps (float): A small number to avoid division
| 17 | |
| 18 | @R.register("tasks.TorsionalDiffusion") |
| 19 | class TorsionalDiffusion(tasks.Task, core.Configurable): |
| 20 | """ |
| 21 | NewTorsionalDiffusion is a class for simulating the torsional diffusion of a protein model. |
| 22 | |
| 23 | It inherits from the tasks.Task and core.Configurable classes and uses these to setup and control the diffusion |
| 24 | simulation. |
| 25 | |
| 26 | Attributes: |
| 27 | eps (float): A small number to avoid division by zero errors. |
| 28 | _option_members (set): A set containing the names of class attributes. |
| 29 | model (nn.Module): The neural network model to be used. |
| 30 | schedule_1pi_periodic (SO2VESchedule): The schedule for 1pi periodic tasks. |
| 31 | schedule_2pi_periodic (SO2VESchedule): The schedule for 2pi periodic tasks. |
| 32 | num_mlp_layer (int): The number of layers in the model. |
| 33 | graph_construction_model (Optional[Any]): The model used for graph construction. |
| 34 | verbose (int): Verbosity level. |
| 35 | train_chi_id (Optional[Any]): Chi angle for training ranging from 0 to 3. If not specified, random chi angles are trained. |
| 36 | """ |
| 37 | NUM_CHI_ANGLES = 4 |
| 38 | eps = 1e-10 |
| 39 | _option_members = {"task", "criterion", "metric"} |
| 40 | |
| 41 | def __init__(self, sigma_embedding: nn.Module, |
| 42 | model: nn.Module, |
| 43 | torsion_mlp_hidden_dims: list, |
| 44 | schedule_1pi_periodic: SO2VESchedule, |
| 45 | schedule_2pi_periodic: SO2VESchedule, |
| 46 | graph_construction_model: Optional[Any] = None, |
| 47 | verbose: int = 0, |
| 48 | train_chi_id: Optional[Any] = None, ): |
| 49 | super(TorsionalDiffusion, self).__init__() |
| 50 | self.torsion_mlp_hidden_dims = torsion_mlp_hidden_dims |
| 51 | self.model_list = nn.ModuleList([deepcopy(model) for _ in range(self.NUM_CHI_ANGLES)]) |
| 52 | self.sigma_embedding_list = nn.ModuleList([deepcopy(sigma_embedding) for _ in range(self.NUM_CHI_ANGLES)]) |
| 53 | self.torsion_mlp_list = nn.ModuleList([layers.MLP(self.model_list[i].output_dim, torsion_mlp_hidden_dims |
| 54 | + [4,]) for i in range(self.NUM_CHI_ANGLES)]) |
| 55 | self.schedule_2pi_periodic = schedule_2pi_periodic |
| 56 | self.schedule_1pi_periodic = schedule_1pi_periodic |
| 57 | self.graph_construction_model = graph_construction_model |
| 58 | self.verbose = verbose |
| 59 | self.train_chi_id = train_chi_id |
| 60 | |
| 61 | def forward(self, batch): |
| 62 | all_loss = torch.tensor(0, dtype=torch.float32, device=self.device) |
| 63 | metric = {} |
| 64 | |
| 65 | # Sample from the schedule |
| 66 | protein = batch['graph'] |
| 67 | t = self.schedule_1pi_periodic.sample_train_t(shape=(protein.batch_size,)).to(self.device) |
| 68 | |
| 69 | # Add noise to protein |
| 70 | train_chi_id = np.random.randint(self.NUM_CHI_ANGLES) if self.train_chi_id is None else self.train_chi_id |
| 71 | batch = self.add_noise(batch, t, chi_id=train_chi_id) |
| 72 | |
| 73 | # Predict and take loss |
| 74 | pred = self.predict(batch, all_loss, metric) |
| 75 | target = self.target(batch) |
| 76 |
nothing calls this directly
no outgoing calls
no test coverage detected