Пример #1
0
    def test_freeze_radius(self, system_cfg):
        print('Testing freeze_radius')
        freeze_cfg = {'freeze_center': ':LIG', 'freeze_solvent': ':Cl-', 'freeze_distance': 3.0 * unit.angstroms}
        # Setup toluene-T4 lysozyme system
        prmtop = utils.get_data_filename('blues', 'tests/data/TOL-parm.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/TOL-parm.inpcrd')
        structure = parmed.load_file(prmtop, xyz=inpcrd)
        atom_indices = utils.atomIndexfromTop('LIG', structure.topology)
        system = SystemFactory.generateSystem(structure, **system_cfg)

        # Freeze everything around the binding site
        frzn_sys = SystemFactory.freeze_radius(structure, system, **freeze_cfg)

        # Check that the ligand has NOT been frozen
        lig_masses = [system.getParticleMass(i)._value for i in atom_indices]
        assert all(m != 0 for m in lig_masses)

        # Check that the binding site has NOT been frozen
        selection = "({freeze_center}<:{freeze_distance._value})&!({freeze_solvent})".format(**freeze_cfg)
        site_idx = SystemFactory.amber_selection_to_atomidx(structure, selection)
        masses = [frzn_sys.getParticleMass(i)._value for i in site_idx]
        assert all(m != 0 for m in masses)

        # Check that the selection has been frozen
        # Invert that selection to freeze everything but the binding site.
        freeze_idx = set(range(system.getNumParticles())) - set(site_idx)
        massless = [frzn_sys.getParticleMass(i)._value for i in freeze_idx]
        assert all(m == 0 for m in massless)
Пример #2
0
    def test_freeze_radius(self, system_cfg):
        print('Testing freeze_radius')
        freeze_cfg = {
            'freeze_center': ':LIG',
            'freeze_solvent': ':Cl-',
            'freeze_distance': 3.0 * unit.angstroms
        }
        # Setup toluene-T4 lysozyme system
        prmtop = utils.get_data_filename('blues', 'tests/data/TOL-parm.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/TOL-parm.inpcrd')
        structure = parmed.load_file(prmtop, xyz=inpcrd)
        atom_indices = utils.atomIndexfromTop('LIG', structure.topology)
        system = SystemFactory.generateSystem(structure, **system_cfg)

        # Freeze everything around the binding site
        frzn_sys = SystemFactory.freeze_radius(structure, system, **freeze_cfg)

        # Check that the ligand has NOT been frozen
        lig_masses = [system.getParticleMass(i)._value for i in atom_indices]
        assert all(m != 0 for m in lig_masses)

        # Check that the binding site has NOT been frozen
        selection = "({freeze_center}<:{freeze_distance._value})&!({freeze_solvent})".format(
            **freeze_cfg)
        site_idx = SystemFactory.amber_selection_to_atomidx(
            structure, selection)
        masses = [frzn_sys.getParticleMass(i)._value for i in site_idx]
        assert all(m != 0 for m in masses)

        # Check that the selection has been frozen
        # Invert that selection to freeze everything but the binding site.
        freeze_idx = set(range(system.getNumParticles())) - set(site_idx)
        massless = [frzn_sys.getParticleMass(i)._value for i in freeze_idx]
        assert all(m == 0 for m in massless)
Пример #3
0
    def test_freeze_radius(self):
        print('Testing freeze_radius')
        freeze_cfg = {
            'freeze_center': ':LIG',
            'freeze_solvent': ':WAT,Cl-',
            'freeze_distance': 5.0 * unit.angstroms
        }
        frzn_sys = SystemFactory.freeze_radius(self.structure, self.systems.md,
                                               **freeze_cfg)

        selection = "({freeze_center}<:{freeze_distance._value})&!({freeze_solvent})".format(
            **freeze_cfg)
        site_idx = SystemFactory._amber_selection_to_atom_indices_(
            self.structure, selection)
        #Invert that selection to freeze everything but the binding site.
        freeze_idx = set(range(
            self.systems.md.getNumParticles())) - set(site_idx)

        #Check that the ligand has NOT been frozen
        lig_masses = [frzn_sys.getParticleMass(i) for i in self.atom_indices]
        self.assertNotEqual(lig_masses, 0)
        #Check that the binding site has NOT been frozen
        masses = [frzn_sys.getParticleMass(i) for i in site_idx]
        self.assertNotEqual(masses, 0)
        #Check that the selection has been frozen
        massless = set(
            [frzn_sys.getParticleMass(i)._value for i in freeze_idx])
        self.assertEqual(list(massless)[0], 0)
Пример #4
0
    def test_atom_selections(self, structure, tol_atom_indices):
        atom_indices = SystemFactory.amber_selection_to_atomidx(
            structure, ':LIG')

        print('Testing AMBER selection parser')
        assert isinstance(atom_indices, list)
        assert len(atom_indices) == len(tol_atom_indices)
Пример #5
0
    def setUp(self):
        # Load the waterbox with toluene into a structure.
        self.prmtop = utils.get_data_filename('blues',
                                              'tests/data/TOL-parm.prmtop')
        self.inpcrd = utils.get_data_filename('blues',
                                              'tests/data/TOL-parm.inpcrd')
        self.structure = parmed.load_file(self.prmtop, xyz=self.inpcrd)
        self.atom_indices = utils.atomIndexfromTop('LIG',
                                                   self.structure.topology)

        self.system_cfg = {
            'nonbondedMethod': app.PME,
            'nonbondedCutoff': 8.0 * unit.angstroms,
            'constraints': app.HBonds
        }
        self.systems = SystemFactory(self.structure, self.atom_indices,
                                     self.system_cfg)
Пример #6
0
    def test_freeze_atoms(self, structure, system, tol_atom_indices):
        print('Testing freeze_atoms')
        masses = [system.getParticleMass(i)._value for i in tol_atom_indices]
        frzn_lig = SystemFactory.freeze_atoms(structure, system, ':LIG')
        massless = [frzn_lig.getParticleMass(i)._value for i in tol_atom_indices]

        # Check that masses have been zeroed
        assert massless != masses
        assert all(m == 0 for m in massless)
Пример #7
0
    def test_generateSystem(self, structure, system, system_cfg):
        # Create the OpenMM system
        print('Creating OpenMM System')
        md_system = SystemFactory.generateSystem(structure, **system_cfg)

        # Check that we get an openmm.System
        assert isinstance(md_system, openmm.System)
        # Check atoms in system is same in input parmed.Structure
        assert md_system.getNumParticles() == len(structure.atoms)
        assert md_system.getNumParticles() == system.getNumParticles()
Пример #8
0
 def test_freeze_atoms(self):
     print('Testing freeze_atoms')
     masses = [
         self.systems.md.getParticleMass(i) for i in self.atom_indices
     ]
     frzn_lig = SystemFactory.freeze_atoms(self.structure, self.systems.md,
                                           ':LIG')
     massless = [frzn_lig.getParticleMass(i) for i in self.atom_indices]
     #Check that masses have been zeroed
     self.assertNotEqual(massless, masses)
Пример #9
0
    def test_generateSystem(self, structure, system, system_cfg):
        # Create the OpenMM system
        print('Creating OpenMM System')
        md_system = SystemFactory.generateSystem(structure, **system_cfg)

        # Check that we get an openmm.System
        assert isinstance(md_system, openmm.System)
        # Check atoms in system is same in input parmed.Structure
        assert md_system.getNumParticles() == len(structure.atoms)
        assert md_system.getNumParticles() == system.getNumParticles()
Пример #10
0
    def test_freeze_atoms(self, structure, system, tol_atom_indices):
        print('Testing freeze_atoms')
        masses = [system.getParticleMass(i)._value for i in tol_atom_indices]
        frzn_lig = SystemFactory.freeze_atoms(structure, system, ':LIG')
        massless = [
            frzn_lig.getParticleMass(i)._value for i in tol_atom_indices
        ]

        # Check that masses have been zeroed
        assert massless != masses
        assert all(m == 0 for m in massless)
Пример #11
0
    def test_restrain_postions(self, structure, system):
        print('Testing positional restraints')
        no_restr = system.getForces()

        md_system_restr = SystemFactory.restrain_positions(structure, system, ':LIG')
        restr = md_system_restr.getForces()

        # Check that forces have been added to the system.
        assert len(restr) != len(no_restr)
        # Check that it has added the CustomExternalForce
        assert isinstance(restr[-1], openmm.CustomExternalForce)
Пример #12
0
    def test_restrain_postions(self):
        print('Testing positional restraints')
        no_restr = self.systems.md.getForces()

        md_system_restr = SystemFactory.restrain_positions(
            self.structure, self.systems.md, ':LIG')
        restr = md_system_restr.getForces()

        #Check that forces have been added to the system.
        self.assertNotEqual(len(restr), len(no_restr))
        #Check that it has added the CustomExternalForce
        self.assertIsInstance(restr[-1], openmm.CustomExternalForce)
Пример #13
0
    def test_restrain_postions(self, structure, system):
        print('Testing positional restraints')
        no_restr = system.getForces()

        md_system_restr = SystemFactory.restrain_positions(
            structure, system, ':LIG')
        restr = md_system_restr.getForces()

        # Check that forces have been added to the system.
        assert len(restr) != len(no_restr)
        # Check that it has added the CustomExternalForce
        assert isinstance(restr[-1], openmm.CustomExternalForce)
Пример #14
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = testsystems.get_data_filename(
            "data/alanine-dipeptide-gbsa/alanine-dipeptide.prmtop")
        inpcrd = testsystems.get_data_filename(
            "data/alanine-dipeptide-gbsa/alanine-dipeptide.crd")
        testsystem = testsystems.AlanineDipeptideVacuum(constraints=None)
        structure = parmed.openmm.topsystem.load_topology(
            topology=testsystem.topology,
            system=testsystem.system,
            xyz=testsystem.positions)

        #Initialize the Model object
        basis_particles = [0, 2, 7]
        self.move = SmartDartMove(structure,
                                  basis_particles=basis_particles,
                                  coord_files=[inpcrd, inpcrd],
                                  topology=prmtop,
                                  resname='ALA',
                                  self_dart=True)
        self.move.atom_indices = range(22)
        self.move.topology = structure.topology
        self.move.positions = structure.positions
        self.move_engine = MoveEngine(self.move)

        self.system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }
        self.systems = SystemFactory(structure, self.move.atom_indices,
                                     self.system_cfg)

        #Initialize the SimulationFactory object
        self.cfg = {
            'dt': 0.002 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 10,
            'nstepsMD': 50,
            'nstepsNC': 10,
            'alchemical_functions': {
                'lambda_sterics':
                'step(0.199999-lambda) + step(lambda-0.2)*step(0.8-lambda)*abs(lambda-0.5)*1/0.3 + step(lambda-0.800001)',
                'lambda_electrostatics':
                'step(0.2-lambda)- 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)'
            }
        }
        sims = SimulationFactory(self.systems, self.move_engine, self.cfg)
        self.ncmc_sim = sims.ncmc
        self.move.calculateProperties()
        self.initial_positions = self.ncmc_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)
Пример #15
0
    def test_generate_systems(self):
        # Create the OpenMM system
        print('Creating OpenMM System')
        md_system = SystemFactory.generateSystem(self.structure,
                                                 **self.system_cfg)

        # Check that we get an openmm.System
        self.assertIsInstance(md_system, openmm.System)
        # Check atoms in system is same in input parmed.Structure
        self.assertEqual(md_system.getNumParticles(),
                         len(self.structure.atoms))

        # Create the OpenMM system
        print('Creating OpenMM Alchemical System')
        alch_system = SystemFactory.generateAlchSystem(md_system,
                                                       self.atom_indices)

        # Check that we get an openmm.System
        self.assertIsInstance(alch_system, openmm.System)
        # Check atoms in system is same in input parmed.Structure
        self.assertEqual(alch_system.getNumParticles(),
                         len(self.structure.atoms))
Пример #16
0
    def test_atom_selections(self):
        atom_indices = self.systems._amber_selection_to_atom_indices_(
            self.structure, ':LIG')

        print('Testing AMBER selection parser')
        self.assertIsInstance(atom_indices, list)
        self.assertEqual(len(atom_indices), len(self.atom_indices))

        print('Testing atoms from AMBER selection with parmed.Structure')
        atom_list = SystemFactory._print_atomlist_from_atom_indices_(
            self.structure, atom_indices)
        atom_selection = [self.structure.atoms[i] for i in atom_indices]
        self.assertEqual(atom_selection, atom_list)
Пример #17
0
 def setUp(self):
     testsystem = testsystems.AlanineDipeptideVacuum(constraints=None)
     self.structure = parmed.openmm.topsystem.load_topology(
         topology=testsystem.topology,
         system=testsystem.system,
         xyz=testsystem.positions)
     self.move = RandomLigandRotationMove(self.structure, 'ALA')
     self.engine = MoveEngine(self.move)
     system_cfg = {
         'nonbondedMethod': app.NoCutoff,
         'constraints': app.HBonds
     }
     self.systems = SystemFactory(self.structure, self.move.atom_indices,
                                  system_cfg)
Пример #18
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues', 'tests/data/TOL-parm.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/TOL-parm.inpcrd')
        structure = parmed.load_file(prmtop, xyz=inpcrd)

        self.atom_indices = utils.atomIndexfromTop('LIG', structure.topology)

        #Initialize the SmartDartMove object
        self.move = SmartDartMove(
            structure,
            basis_particles=[100, 110, 150],
            coord_files=[inpcrd, inpcrd],
            topology=prmtop,
            self_dart=False,
            resname='LIG',
        )
        self.engine = MoveEngine(self.move)
        self.engine.selectMove()

        self.system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }
        systems = SystemFactory(structure, self.move.atom_indices,
                                self.system_cfg)

        #Initialize the SimulationFactory object
        self.cfg = {
            'dt': 0.002 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 10,
            'nstepsMD': 50,
            'nstepsNC': 10,
            'alchemical_functions': {
                'lambda_sterics':
                'step(0.199999-lambda) + step(lambda-0.2)*step(0.8-lambda)*abs(lambda-0.5)*1/0.3 + step(lambda-0.800001)',
                'lambda_electrostatics':
                'step(0.2-lambda)- 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)'
            }
        }
        sims = SimulationFactory(systems, self.engine, self.cfg)
        self.ncmc_sim = sims.ncmc

        self.initial_positions = self.ncmc_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)
Пример #19
0
    def test_generateAlchSystem(self, structure, system, tol_atom_indices):
        # Create the OpenMM system
        print('Creating OpenMM Alchemical System')
        alch_system = SystemFactory.generateAlchSystem(system, tol_atom_indices)

        # Check that we get an openmm.System
        assert isinstance(alch_system, openmm.System)

        # Check atoms in system is same in input parmed.Structure
        assert alch_system.getNumParticles() == len(structure.atoms)
        assert alch_system.getNumParticles() == system.getNumParticles()

        # Check customforces were added for the Alchemical system
        alch_forces = alch_system.getForces()
        alch_force_names = [force.__class__.__name__ for force in alch_forces]
        assert len(system.getForces()) < len(alch_forces)
        assert len(fnmatch.filter(alch_force_names, 'Custom*Force')) > 0
Пример #20
0
    def test_generateAlchSystem(self, structure, system, tol_atom_indices):
        # Create the OpenMM system
        print('Creating OpenMM Alchemical System')
        alch_system = SystemFactory.generateAlchSystem(system,
                                                       tol_atom_indices)

        # Check that we get an openmm.System
        assert isinstance(alch_system, openmm.System)

        # Check atoms in system is same in input parmed.Structure
        assert alch_system.getNumParticles() == len(structure.atoms)
        assert alch_system.getNumParticles() == system.getNumParticles()

        # Check customforces were added for the Alchemical system
        alch_forces = alch_system.getForces()
        alch_force_names = [force.__class__.__name__ for force in alch_forces]
        assert len(system.getForces()) < len(alch_forces)
        assert len(fnmatch.filter(alch_force_names, 'Custom*Force')) > 0
Пример #21
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues',
                                         'tests/data/eqToluene.prmtop')
        inpcrd = utils.get_data_filename('blues', 'tests/data/eqToluene.pdb')
        structure = parmed.load_file(prmtop, xyz=inpcrd)

        #Initialize the Move object
        self.move = WaterTranslationMove(
            structure,
            protein_selection='(index 1656) or (index 1657)',
            radius=0.9 * unit.nanometer)
        self.atom_indices = self.move.atom_indices

        self.engine = MoveEngine(self.move)
        self.engine.selectMove()

        self.system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }
        systems = SystemFactory(structure, self.move.atom_indices,
                                self.system_cfg)

        #Initialize the SimulationFactory object
        self.cfg = {
            'dt': 0.002 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nprop': 1,
            'nIter': 1,
            'nstepsMD': 1,
            'nstepsNC': 100,
            'alchemical_functions': {
                'lambda_sterics':
                'step(0.199999-lambda) + step(lambda-0.2)*step(0.8-lambda)*abs(lambda-0.5)*1/0.3 + step(lambda-0.800001)',
                'lambda_electrostatics':
                'step(0.2-lambda)- 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)'
            }
        }
        self.simulations = SimulationFactory(systems, self.engine, self.cfg)
        self.ncmc_sim = self.simulations.ncmc
        self.initial_positions = self.ncmc_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)
Пример #22
0
    def setUp(self):
        # Obtain topologies/positions
        prmtop = utils.get_data_filename('blues',
                                         'tests/data/vacDivaline.prmtop')
        inpcrd = utils.get_data_filename('blues',
                                         'tests/data/vacDivaline.inpcrd')
        self.struct = parmed.load_file(prmtop, xyz=inpcrd)

        self.sidechain = SideChainMove(self.struct, [1])
        self.engine = MoveEngine(self.sidechain)
        self.engine.selectMove()

        self.system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }
        self.systems = SystemFactory(self.struct, self.sidechain.atom_indices,
                                     self.system_cfg)

        self.cfg = {
            'dt': 0.002 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 1,
            'nstepsMD': 1,
            'nstepsNC': 4,
            'alchemical_functions': {
                'lambda_sterics':
                'step(0.199999-lambda) + step(lambda-0.2)*step(0.8-lambda)*abs(lambda-0.5)*1/0.3 + step(lambda-0.800001)',
                'lambda_electrostatics':
                'step(0.2-lambda)- 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)'
            }
        }

        self.simulations = SimulationFactory(self.systems, self.engine,
                                             self.cfg)
Пример #23
0
class SystemFactoryTester(unittest.TestCase):
    """
    Test the SystemFactory class.
    """
    def setUp(self):
        # Load the waterbox with toluene into a structure.
        self.prmtop = utils.get_data_filename('blues',
                                              'tests/data/TOL-parm.prmtop')
        self.inpcrd = utils.get_data_filename('blues',
                                              'tests/data/TOL-parm.inpcrd')
        self.structure = parmed.load_file(self.prmtop, xyz=self.inpcrd)
        self.atom_indices = utils.atomIndexfromTop('LIG',
                                                   self.structure.topology)

        self.system_cfg = {
            'nonbondedMethod': app.PME,
            'nonbondedCutoff': 8.0 * unit.angstroms,
            'constraints': app.HBonds
        }
        self.systems = SystemFactory(self.structure, self.atom_indices,
                                     self.system_cfg)

    def test_generate_systems(self):
        # Create the OpenMM system
        print('Creating OpenMM System')
        md_system = SystemFactory.generateSystem(self.structure,
                                                 **self.system_cfg)

        # Check that we get an openmm.System
        self.assertIsInstance(md_system, openmm.System)
        # Check atoms in system is same in input parmed.Structure
        self.assertEqual(md_system.getNumParticles(),
                         len(self.structure.atoms))

        # Create the OpenMM system
        print('Creating OpenMM Alchemical System')
        alch_system = SystemFactory.generateAlchSystem(md_system,
                                                       self.atom_indices)

        # Check that we get an openmm.System
        self.assertIsInstance(alch_system, openmm.System)
        # Check atoms in system is same in input parmed.Structure
        self.assertEqual(alch_system.getNumParticles(),
                         len(self.structure.atoms))

    def test_atom_selections(self):
        atom_indices = self.systems._amber_selection_to_atom_indices_(
            self.structure, ':LIG')

        print('Testing AMBER selection parser')
        self.assertIsInstance(atom_indices, list)
        self.assertEqual(len(atom_indices), len(self.atom_indices))

        print('Testing atoms from AMBER selection with parmed.Structure')
        atom_list = SystemFactory._print_atomlist_from_atom_indices_(
            self.structure, atom_indices)
        atom_selection = [self.structure.atoms[i] for i in atom_indices]
        self.assertEqual(atom_selection, atom_list)

    def test_restrain_postions(self):
        print('Testing positional restraints')
        no_restr = self.systems.md.getForces()

        md_system_restr = SystemFactory.restrain_positions(
            self.structure, self.systems.md, ':LIG')
        restr = md_system_restr.getForces()

        #Check that forces have been added to the system.
        self.assertNotEqual(len(restr), len(no_restr))
        #Check that it has added the CustomExternalForce
        self.assertIsInstance(restr[-1], openmm.CustomExternalForce)

    def test_freeze_atoms(self):
        print('Testing freeze_atoms')
        masses = [
            self.systems.md.getParticleMass(i) for i in self.atom_indices
        ]
        frzn_lig = SystemFactory.freeze_atoms(self.structure, self.systems.md,
                                              ':LIG')
        massless = [frzn_lig.getParticleMass(i) for i in self.atom_indices]
        #Check that masses have been zeroed
        self.assertNotEqual(massless, masses)

    def test_freeze_radius(self):
        print('Testing freeze_radius')
        freeze_cfg = {
            'freeze_center': ':LIG',
            'freeze_solvent': ':WAT,Cl-',
            'freeze_distance': 5.0 * unit.angstroms
        }
        frzn_sys = SystemFactory.freeze_radius(self.structure, self.systems.md,
                                               **freeze_cfg)

        selection = "({freeze_center}<:{freeze_distance._value})&!({freeze_solvent})".format(
            **freeze_cfg)
        site_idx = SystemFactory._amber_selection_to_atom_indices_(
            self.structure, selection)
        #Invert that selection to freeze everything but the binding site.
        freeze_idx = set(range(
            self.systems.md.getNumParticles())) - set(site_idx)

        #Check that the ligand has NOT been frozen
        lig_masses = [frzn_sys.getParticleMass(i) for i in self.atom_indices]
        self.assertNotEqual(lig_masses, 0)
        #Check that the binding site has NOT been frozen
        masses = [frzn_sys.getParticleMass(i) for i in site_idx]
        self.assertNotEqual(masses, 0)
        #Check that the selection has been frozen
        massless = set(
            [frzn_sys.getParticleMass(i)._value for i in freeze_idx])
        self.assertEqual(list(massless)[0], 0)
Пример #24
0
def systems(structure, tol_atom_indices, system_cfg):
    systems = SystemFactory(structure, tol_atom_indices, system_cfg)
    return systems
Пример #25
0
 def test_atomidx_to_atomlist(self, structure, tol_atom_indices):
     print('Testing atoms from AMBER selection with parmed.Structure')
     atom_list = SystemFactory.atomidx_to_atomlist(structure,
                                                   tol_atom_indices)
     atom_selection = [structure.atoms[i] for i in tol_atom_indices]
     assert atom_selection == atom_list
Пример #26
0
    def test_blues_simulationRunYAML(self, tmpdir, structure, tol_atom_indices,
                                     system_cfg, engine):
        yaml_cfg = """
            output_dir: .
            outfname: tol-test
            logger:
              level: info
              stream: True

            system:
              nonbondedMethod: PME
              nonbondedCutoff: 8.0 * angstroms
              constraints: HBonds

            simulation:
              dt: 0.002 * picoseconds
              friction: 1 * 1/picoseconds
              temperature: 300 * kelvin
              nIter: 1
              nstepsMD: 2
              nstepsNC: 2
              platform: CPU

            md_reporters:
              stream:
                title: md
                reportInterval: 1
                totalSteps: 2 # nIter * nstepsMD
                step: True
                speed: True
                progress: True
                remainingTime: True
                currentIter : True
            ncmc_reporters:
              stream:
                title: ncmc
                reportInterval: 1
                totalSteps: 2 # Use nstepsNC
                step: True
                speed: True
                progress: True
                remainingTime: True
                protocolWork : True
                alchemicalLambda : True
                currentIter : True
        """
        print('Testing Simulation.run() from YAML')
        yaml_cfg = Settings(yaml_cfg)
        cfg = yaml_cfg.asDict()
        cfg['output_dir'] = tmpdir
        # os.getenv is equivalent, and can also give a default value instead of `None`
        PLATFORM = os.getenv('OMM_PLATFORM', 'CPU')
        cfg['simulation']['platform'] = PLATFORM
        systems = SystemFactory(structure, tol_atom_indices, cfg['system'])
        simulations = SimulationFactory(systems, engine, cfg['simulation'],
                                        cfg['md_reporters'],
                                        cfg['ncmc_reporters'])

        blues = BLUESSimulation(simulations)
        blues._md_sim.minimizeEnergy()
        blues._alch_sim.minimizeEnergy()
        blues._ncmc_sim.minimizeEnergy()
        before_iter = blues._md_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)
        blues.run()
        after_iter = blues._md_sim.context.getState(
            getPositions=True).getPositions(asNumpy=True)
        #Check that our system has run dynamics
        pos_compare = np.not_equal(before_iter, after_iter).all()
        assert pos_compare
Пример #27
0
 def test_atomidx_to_atomlist(self, structure, tol_atom_indices):
     print('Testing atoms from AMBER selection with parmed.Structure')
     atom_list = SystemFactory.atomidx_to_atomlist(structure, tol_atom_indices)
     atom_selection = [structure.atoms[i] for i in tol_atom_indices]
     assert atom_selection == atom_list
Пример #28
0
    def test_atom_selections(self, structure, tol_atom_indices):
        atom_indices = SystemFactory.amber_selection_to_atomidx(structure, ':LIG')

        print('Testing AMBER selection parser')
        assert isinstance(atom_indices, list)
        assert len(atom_indices) == len(tol_atom_indices)
Пример #29
0
def runEthyleneTest(N):
    filename = 'ethylene-test_%s' % N
    print('Running %s...' % filename)
    seed = np.random.randint(low=1, high=5000)
    #print('Seed', seed)
    # filename = 'ethylene-test_%s' % N
    # print(filename)

    # Set Simulation parameters
    sim_cfg = {
        'platform': 'CPU',
        'nprop': 1,
        'propLambda': 0.3,
        'dt': 1 * unit.femtoseconds,
        'friction': 1 / unit.picoseconds,
        'temperature': 200 * unit.kelvin,
        'nIter': 100,
        'nstepsMD': 20,
        'nstepsNC': 20,
        'propSteps': 20,
        'moveStep': 10
    }

    totalSteps = int(sim_cfg['nIter'] * sim_cfg['nstepsMD'])
    reportInterval = 5
    alchemical_atoms = [2, 3, 4, 5, 6, 7]
    alchemical_functions = {
        'lambda_sterics':
        'min(1, (1/0.3)*abs(lambda-0.5))',
        'lambda_electrostatics':
        'step(0.2-lambda) - 1/0.2*lambda*step(0.2-lambda) + 1/0.2*(lambda-0.8)*step(lambda-0.8)'
    }

    md_reporters = {'traj_netcdf': {'reportInterval': reportInterval}}

    # Load a Parmed Structure for the Topology and create our openmm.Simulation
    structure_pdb = utils.get_data_filename(
        'blues', 'tests/data/ethylene_structure.pdb')
    structure = parmed.load_file(structure_pdb)

    # Initialize our move proposal class
    rot_move = RandomLigandRotationMove(structure, 'LIG')
    mover = MoveEngine(rot_move)

    # Load our OpenMM System and create Integrator
    system_xml = utils.get_data_filename('blues',
                                         'tests/data/ethylene_system.xml')
    with open(system_xml, 'r') as infile:
        xml = infile.read()
        system = openmm.XmlSerializer.deserialize(xml)
    integrator = openmm.LangevinIntegrator(sim_cfg['temperature'],
                                           sim_cfg['friction'], sim_cfg['dt'])
    integrator.setRandomNumberSeed(seed)

    alch_integrator = openmm.LangevinIntegrator(sim_cfg['temperature'],
                                                sim_cfg['friction'],
                                                sim_cfg['dt'])
    alch_integrator.setRandomNumberSeed(seed)

    alch_system = SystemFactory.generateAlchSystem(system, alchemical_atoms)
    ncmc_integrator = AlchemicalExternalLangevinIntegrator(
        nsteps_neq=sim_cfg['nstepsNC'],
        alchemical_functions=alchemical_functions,
        splitting="H V R O R V H",
        temperature=sim_cfg['temperature'],
        timestep=sim_cfg['dt'])
    # ncmc_integrator.setRandomNumberSeed(seed)

    # Pack our systems into a single object
    systems = SystemFactory(structure, alchemical_atoms)
    systems.md = system
    systems.alch = alch_system

    # Make our reporters
    md_reporter_cfg = ReporterConfig(filename, md_reporters)
    md_reporters_list = md_reporter_cfg.makeReporters()

    # Pack our simulations into a single object
    simulations = SimulationFactory(systems, mover)

    simulations.md = SimulationFactory.generateSimFromStruct(
        structure, system, integrator, 'CPU')
    simulations.md = SimulationFactory.attachReporters(simulations.md,
                                                       md_reporters_list)

    simulations.alch = SimulationFactory.generateSimFromStruct(
        structure, system, alch_integrator, 'CPU')

    simulations.ncmc = SimulationFactory.generateSimFromStruct(
        structure, alch_system, ncmc_integrator, 'CPU')

    ethylene_sim = BLUESSimulation(simulations, sim_cfg)
    ethylene_sim.run()
Пример #30
0
    def setUp(self):

        prmtop = testsystems.get_data_filename(
            "data/alanine-dipeptide-explicit/alanine-dipeptide.prmtop")
        inpcrd = testsystems.get_data_filename(
            "data/alanine-dipeptide-explicit/alanine-dipeptide.crd")
        self.structure = parmed.load_file(prmtop, xyz=inpcrd)

        class SetRotationMove(RandomLigandRotationMove):
            def __init__(self, structure, resname='ALA'):
                super(SetRotationMove, self).__init__(structure, resname)

            def move(self, context):
                """Function that performs a random rotation about the
                center of mass of the ligand. Define a set rotation
                for reproducibility
                """
                positions = context.getState(getPositions=True).getPositions(
                    asNumpy=True)

                self.positions = positions[self.atom_indices]
                self.center_of_mass = self.getCenterOfMass(
                    self.positions, self.masses)
                reduced_pos = self.positions - self.center_of_mass

                # Define random rotational move on the ligand
                #set rotation so that test is reproducible
                set_rotation_matrix = np.array(
                    [[-0.62297988, -0.17349253, 0.7627558],
                     [0.55082352, -0.78964857, 0.27027502],
                     [0.55541834, 0.58851973, 0.58749893]])

                #multiply lig coordinates by rot matrix and add back COM translation from origin
                rot_move = np.dot(reduced_pos, set_rotation_matrix
                                  ) * positions.unit + self.center_of_mass

                # Update ligand positions in nc_sim
                for index, atomidx in enumerate(self.atom_indices):
                    positions[atomidx] = rot_move[index]
                context.setPositions(positions)
                positions = context.getState(getPositions=True).getPositions(
                    asNumpy=True)
                self.positions = positions[self.atom_indices]
                return context

        self.move = SetRotationMove(self.structure, resname='ALA')
        self.move.atom_indices = range(22)
        self.move.topology = self.structure[self.move.atom_indices].topology
        self.move.positions = self.structure[self.move.atom_indices].positions
        self.move.calculateProperties()

        self.engine = MoveEngine(self.move)

        system_cfg = {
            'nonbondedMethod': app.NoCutoff,
            'constraints': app.HBonds
        }

        #self.systems = self.structure.createSystem(**system_cfg)
        self.systems = SystemFactory(self.structure, self.move.atom_indices,
                                     system_cfg)

        mc_rep_cfg = {
            'stream': {
                'title': 'mc',
                'reportInterval': 1,
                'totalSteps': 4,
                'step': True,
                'speed': True,
                'progress': True,
                'remainingTime': True,
                'currentIter': True
            }
        }
        mc_reporters = ReporterConfig('ala-dipep-vac',
                                      mc_rep_cfg).makeReporters()

        cfg = {
            'nprop': 1,
            'dt': 0.000021 * unit.picoseconds,
            'friction': 1 * 1 / unit.picoseconds,
            'temperature': 300 * unit.kelvin,
            'nIter': 2,
            'nstepsMD': 1,
            'mc_per_iter': 2
        }
        self.simulations = SimulationFactory(self.systems,
                                             self.engine,
                                             cfg,
                                             md_reporters=mc_reporters)