Coverage for ufedmm/testmodels.py: 100%
27 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-02 04:20 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-02 04:20 +0000
1"""
2.. module:: testmodels
3 :platform: Unix, Windows
4 :synopsis: Unified Free Energy Dynamics Test Model Systems
6.. moduleauthor:: Charlles Abreu <abreu@eq.ufrj.br>
8.. _System:
9 http://docs.openmm.org/latest/api-python/generated/openmm.openmm.System.html
10.. _Topology:
11 http://docs.openmm.org/latest/api-python/generated/openmm.app.topology.Topology.html
13"""
15import os
17import openmm
18from openmm import app, unit
20import ufedmm
23class AlanineDipeptideModel(object):
24 """A system consisting of a single alanine-dipeptide molecule in a vacuum or
25 solvated in explicit water.
27 Keyword Args
28 ------------
29 force_field : str, default="amber03"
30 The force field to be used for the alanine dipeptide molecule.
31 water : str, default=None
32 The water model to be used if the alanine dipeptide is supposed to be
33 solvated. Available options are "spce", "tip3p", "tip4pew", and "tip5p".
34 box_length : unit.Quantity, default=25*unit.angstroms
35 The size of the simulation box. This is only effective if water is not
36 `None`.
37 constraints : object, default=`openmm.app.HBonds`
38 Specifies which bonds and angles should be implemented with constraints.
39 Allowed values are `None`, `openmm.app.HBonds`, `openmm.app.AllBonds`, or
40 `openmm.app.HAngles`.
41 rigidWater : bool, boolean=True
42 Whether water molecules will be fully rigid regardless of the value passed
43 for the constraints argument.
45 Attributes
46 ----------
47 system : openmm.System
48 The system.
49 topology : openmm.app.Topology
50 The topology.
51 positions : list of openmm.Vec3
52 The positions.
53 phi : openm.CustomTorsionForce
54 The Ramachandran dihedral angle :math:`\\phi` of the alanine dipeptide
55 molecule.
56 psi : openm.CustomTorsionForce
57 The Ramachandran dihedral angle :math:`\\psi` of the alanine dipeptide
58 molecule.
59 """
61 def __init__(
62 self,
63 force_field="amber03",
64 water=None,
65 box_length=25 * unit.angstroms,
66 constraints=openmm.app.HBonds,
67 rigidWater=True,
68 ):
69 pdb = app.PDBFile(
70 os.path.join(ufedmm.__path__[0], "data", "alanine-dipeptide.pdb")
71 )
72 if water is None:
73 force_field = app.ForceField(f"{force_field}.xml")
74 self.topology = pdb.topology
75 self.positions = pdb.positions
76 L = box_length.value_in_unit(unit.nanometers)
77 vectors = [openmm.Vec3(L, 0, 0), openmm.Vec3(0, L, 0), openmm.Vec3(0, 0, L)]
78 self.topology.setPeriodicBoxVectors(vectors)
79 else:
80 force_field = app.ForceField(f"{force_field}.xml", f"{water}.xml")
81 modeller = app.Modeller(pdb.topology, pdb.positions)
82 modeller.addSolvent(
83 force_field, model=water, boxSize=box_length * openmm.Vec3(1, 1, 1)
84 )
85 self.topology = modeller.topology
86 self.positions = modeller.positions
87 self.system = force_field.createSystem(
88 self.topology,
89 nonbondedMethod=app.NoCutoff if water is None else app.PME,
90 constraints=constraints,
91 rigidWater=rigidWater,
92 removeCMMotion=False,
93 )
94 atoms = [(a.name, a.residue.name) for a in self.topology.atoms()]
95 phi_atoms = [("C", "ACE"), ("N", "ALA"), ("CA", "ALA"), ("C", "ALA")]
96 self.phi = ufedmm.CollectiveVariable("phi", openmm.CustomTorsionForce("theta"))
97 self.phi.force.addTorsion(*[atoms.index(i) for i in phi_atoms], [])
98 psi_atoms = [("N", "ALA"), ("CA", "ALA"), ("C", "ALA"), ("N", "NME")]
99 self.psi = ufedmm.CollectiveVariable("psi", openmm.CustomTorsionForce("theta"))
100 self.psi.force.addTorsion(*[atoms.index(i) for i in psi_atoms], [])