Exemple #1
0
    def omm_system(input_sdf,
                   input_system,
                   forcefield,
                   input_path,
                   ff_files=[],
                   template_ff='gaff-2.11'):
        

        
        from openmmforcefields.generators import SystemGenerator, GAFFTemplateGenerator
        from openff.toolkit.topology import Molecule
        
        
        # maybe possible to add same parameters that u give forcefield.createSystem() function
        forcefield_kwargs ={'constraints' : app.HBonds,
                            'rigidWater' : True,
                            'removeCMMotion' : False,
                            'hydrogenMass' : 4*amu }
		
        system_generator = SystemGenerator(forcefields=ff_files, 
                                           small_molecule_forcefield=template_ff,
                                           forcefield_kwargs=forcefield_kwargs, 
                                           cache='db.json')
        

        input_sdfs=[]
        for idx, sdf in enumerate(input_sdf, 1):
        
            
            path_sdf=f'{input_path}/{sdf}'

            if not os.path.exists(path_sdf):
                
                print(f'\tFile {path_sdf} not found!')
            else:
                print(f'\tAdding extra SDF file {idx} to pre-system: {path_sdf}')
                input_sdfs.append(path_sdf)
                       

        molecules = Molecule.from_file(*input_sdfs, file_format='sdf')
        
        print(molecules)
        
        system = system_generator.create_system(topology=input_system.topology)#, molecules=molecules)
        
        
        gaff = GAFFTemplateGenerator(molecules=molecules, forcefield=template_ff)
        gaff.add_molecules(molecules)
        print(gaff)
        forcefield.registerTemplateGenerator(gaff.generator)
        
        #forcefield.registerResidueTemplate(template)
        
        print(system)
        print(forcefield)
        
        
        return system, forcefield
 def test_version(self):
     """Test version"""
     for forcefield in GAFFTemplateGenerator.INSTALLED_FORCEFIELDS:
         generator = GAFFTemplateGenerator(forcefield=forcefield)
         import re
         result = re.match('^gaff-(?P<major_version>\d+)\.(?P<minor_version>\d+)$', forcefield)
         assert generator.forcefield == forcefield
         assert generator.gaff_version == result['major_version'] + '.' + result['minor_version']
         assert generator.gaff_major_version == result['major_version']
         assert generator.gaff_minor_version == result['minor_version']
         assert generator.gaff_dat_filename.endswith(forcefield + '.dat')
         assert os.path.exists(generator.gaff_dat_filename)
         assert generator.gaff_xml_filename.endswith(forcefield + '.xml')
         assert os.path.exists(generator.gaff_xml_filename)
Exemple #3
0
    def _type_gaff(self, g):
        """ Type a molecular graph using gaff force fields.

        """
        # assert the forcefield is indeed of gaff family
        assert "gaff" in self.forcefield

        # make sure mol is in OpenForceField format `
        mol = g.mol

        # import template generator
        from openmmforcefields.generators import GAFFTemplateGenerator

        gaff = GAFFTemplateGenerator(molecules=mol, forcefield=self.forcefield)

        # create temporary directory for running antechamber
        import os
        import shutil
        import tempfile

        tempdir = tempfile.mkdtemp()
        prefix = "molecule"
        input_sdf_filename = os.path.join(tempdir, prefix + ".sdf")
        gaff_mol2_filename = os.path.join(tempdir, prefix + ".gaff.mol2")
        frcmod_filename = os.path.join(tempdir, prefix + ".frcmod")

        # write sdf for input
        mol.to_file(input_sdf_filename, file_format="sdf")

        # run antechamber
        gaff._run_antechamber(
            molecule_filename=input_sdf_filename,
            input_format="mdl",
            gaff_mol2_filename=gaff_mol2_filename,
            frcmod_filename=frcmod_filename,
        )

        gaff._read_gaff_atom_types_from_mol2(gaff_mol2_filename, mol)
        gaff_types = [atom.gaff_type for atom in mol.atoms]
        shutil.rmtree(tempdir)

        # put types into graph object
        if g is None:
            g = esp.Graph(mol)

        g.nodes["n1"].data["legacy_typing"] = torch.tensor(
            [self._str_2_idx[atom] for atom in gaff_types])

        return g
Exemple #4
0
""" Assemble the holo-complex """
molAPO = PDBFile(f'{PDB_DIR}/{SEED_PDB}.fab.fixed.pdb')
molLIG = PDBFile(f'{PDB_DIR}/{TARGET_CID}.pdb')
molSMI = Chem.MolToSmiles(
    molPROBE, isomericSmiles=True, allBondsExplicit=True)

model = Modeller(molAPO.topology, molAPO.getPositions())
model.add(molLIG.topology, molLIG.getPositions())

with open('holo.pdb', 'w+') as outfile:
    PDBFile.writeFile(model.topology, model.getPositions(), outfile)

""" Parameterize the holo-complex """
GAFFForceField = GAFFTemplateGenerator.INSTALLED_FORCEFIELDS[-1]
GAFFTemplate = GAFFTemplateGenerator(forcefield=GAFFForceField)
GAFFTemplate.add_molecules(
    Molecule.from_smiles(molSMI, allow_undefined_stereo=True))
forcefield = app.ForceField('amber14/protein.ff14SB.xml')
forcefield.registerTemplateGenerator(GAFFTemplate.generator)
system00 = forcefield.createSystem(model.topology)

""" Minimize the holo-complex """
holo = app.PDBFile('holo.pdb')

integrator = LangevinIntegrator(
    LANGE_TEMPERATURE, LANGE_FRICTION, LANGE_STEPSIZE)
integrator.setConstraintTolerance(LANGE_TOLERANCE)

simulation = Simulation(holo.topology, system00, integrator)
simulation.context.setPositions(holo.getPositions())