File size: 1,964 Bytes
7efee70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import openmm as mm
import openmm.unit as unit
from openmm import app
from openmmtools.integrators import VVVRIntegrator

from potentials.MoleculePotential import MoleculePotential


class PolyPotentialMD(MoleculePotential):
    def __init__(self, start_file, index, reset_steps=100, save_file=None):
        super().__init__(start_file, index, reset_steps, save_file)

    def setup(self):
        pdb = app.PDBFile(self.start_file)
        forcefield = app.ForceField('amber/protein.ff14SBonlysc.xml',
                                    'implicit/gbn2.xml')
        system = forcefield.createSystem(
            pdb.topology,
            nonbondedMethod=app.NoCutoff,
            nonbondedCutoff=1.0 * unit.nanometers,
            constraints=app.HBonds,
            rigidWater=True,
            ewaldErrorTolerance=0.0005
        )
        external_force = mm.CustomExternalForce("k*(fx*x + fy*y + fz*z)")

        # creating the parameters
        external_force.addGlobalParameter("k", 1000)
        external_force.addPerParticleParameter("fx")
        external_force.addPerParticleParameter("fy")
        external_force.addPerParticleParameter("fz")
        system.addForce(external_force)
        for i in range(len(pdb.positions)):
            external_force.addParticle(i, [0, 0, 0])

        integrator = VVVRIntegrator(
            300 * unit.kelvin,  # temp
            1.0 / unit.picoseconds,  # collision rate
            2.0 * unit.femtoseconds)  # timestep

        integrator.setConstraintTolerance(0.00001)

        platform = mm.Platform.getPlatformByName('CUDA')

        properties = {'DeviceIndex': '0', 'Precision': 'mixed'}

        simulation = app.Simulation(pdb.topology, system, integrator,
                                    platform, properties)
        simulation.context.setPositions(pdb.positions)

        return pdb, simulation, external_force

    def get_position_file(self):
        return f"{self.save_file}/PolyPositions"