Ejemplo n.º 1
0
    def label_molecule(self, molecule: off.Molecule) -> Dict[str, str]:
        """
        Type the molecule with the forcefield and return a molecule parameter dictionary.

        Parameters
        ----------
        molecule: off.Molecule
            The openforcefield.topology.Molecule that should be labeled by the forcefield.

        Returns
        -------
        Dict[str, str]
            A dictionary of each parameter assigned to molecule organised by parameter handler type.
        """
        return self.forcefield.label_molecules(molecule.to_topology())[0]
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser(description='Parameterizes a small \
                                     molecule ligand for use with OpenMM \
                                     using OpenFF')
    parser.add_argument('-l',
                        '--ligand',
                        action='store',
                        nargs=1,
                        dest='ligand',
                        help='The ligand .sdf file to generate \
                        parameters for')
    parser.add_argument('-i',
                        '--input_directory',
                        action='store',
                        nargs=1,
                        dest='input',
                        default=['./'],
                        help='Directory where \
                        input pdb files are stored')
    parser.add_argument('-o',
                        '--output_directory',
                        action='store',
                        nargs=1,
                        dest='output',
                        default=['./'],
                        help='Directory where \
                        output log should be written')
    args = vars(parser.parse_args())

    #Load SDF file from minimize_lig.py
    lig_sdf = args['input'][0] + '/' + args['ligand'][0]
    lig_name = lig_sdf.split('.sdf')[-2]

    lig_off_molecule = Molecule(args['output'][0] + '/' + lig_sdf)
    force_field = ForceField('test_forcefields/smirnoff99Frosst.offxml')
    start = time.time()
    ligand_system = force_field.create_openmm_system(
        lig_off_molecule.to_topology())
    end = time.time()
    print(end - start)

    with open(lig_name + '.xml', 'w') as f:
        f.write(XmlSerializer.serialize(ligand_system))
Ejemplo n.º 3
0
async def run(io):
    print(dir(parmed))
    if not os.path.exists(datapath +
                          'complex.xml') or not os.path.exists(datapath +
                                                               'complex.pdb'):
        print('1: loading Ligand molecule')
        ligand_off_molecule = Molecule(datapath + 'ligand.sdf')

        # Load the SMIRNOFF-format Parsley force field

        #force_field = ForceField('openff_unconstrained-1.0.0.offxml')
        print("2: Loading the Force Field")
        force_field = ForceField('openff_unconstrained-1.2.0.offxml')

        # Parametrize the ligand molecule by creating a Topology object from it
        print("3: Create Ligand System")
        ligand_system = force_field.create_openmm_system(
            ligand_off_molecule.to_topology())
        # Read in the coordinates of the ligand from the PDB file
        ligand_pdbfile = PDBFile(datapath + 'ligand.pdb')

        # Convert OpenMM System object containing ligand parameters into a ParmEd Structure.
        print("4: Transforming Ligand System to Parmed")
        ligand_structure = parmed.openmm.load_topology(
            ligand_pdbfile.topology,
            ligand_system,
            xyz=ligand_pdbfile.positions)

        print("5: Loading the protein pdb file")
        receptor_pdbfile = PDBFile(datapath + 'receptor.pdb')

        # Load the AMBER protein force field through OpenMM.
        omm_forcefield = app.ForceField('amber14-all.xml')

        # Parameterize the protein.
        print("6: Create protein system")
        receptor_system = omm_forcefield.createSystem(
            receptor_pdbfile.topology)

        # Convert the protein System into a ParmEd Structure.
        print("7: Convert protein system to parmed")
        receptor_structure = parmed.openmm.load_topology(
            receptor_pdbfile.topology,
            receptor_system,
            xyz=receptor_pdbfile.positions)

        print("8: Combinding protein & ligand system")
        complex_structure = receptor_structure + ligand_structure

        print(dir(complex_structure))
        print("9: Create Openmm system")
        # Convert the Structure to an OpenMM System in vacuum.
        complex_system = complex_structure.createSystem(
            nonbondedMethod=NoCutoff,
            nonbondedCutoff=9.0 * unit.angstrom,
            constraints=HBonds,
            removeCMMotion=False)

        complex_structure.save(datapath + 'complex.pdb', overwrite=True)
        complex_structure = parmed.load_file(datapath + 'complex.pdb')
        with open(datapath + 'complex.xml', 'w') as f:
            f.write(XmlSerializer.serialize(complex_system))

    complex_structure = parmed.load_file(datapath + 'complex.pdb')

    with open(datapath + 'complex.xml', 'r') as f:
        complex_system = XmlSerializer.deserialize(f.read())

    print(dir(complex_structure))
    platform = openmm.Platform.getPlatformByName('OpenCL')
    properties = {'OpenCLPrecision': 'mixed'}
    integrator = openmm.LangevinIntegrator(300 * unit.kelvin,
                                           91 / unit.picosecond,
                                           0.002 * unit.picoseconds)
    simulation = openmm.app.Simulation(complex_structure, complex_system,
                                       integrator, platform)
    simulation.context.setPositions(complex_structure.positions)
    print("     starting minimization")
    state = simulation.context.getState(getEnergy=True, getForces=True)
    lastEnergy = state.getPotentialEnergy()
    potEnergyValue = state.getPotentialEnergy().value_in_unit(
        unit.kilojoules_per_mole)
    m = '     Starting pot energy: {:.3f} kJ/mol'.format(potEnergyValue)
    print(m)
    await io.emit("setMessage", m)
    # io.emit("setMessage", m)
    t0 = time.time()
    emit_freq = 1
    maxIter = 20
    # iterations=1
    for i in range(100):
        simulation.minimizeEnergy(tolerance=0, maxIterations=maxIter)
        state = simulation.context.getState(getPositions=True, getEnergy=True)
        currentEnergy = state.getPotentialEnergy()
        positions = state.getPositions(
            asNumpy=True) * 10  #convert to angstroms
        p = positions._value.flatten().tolist()
        # if(abs(lastEnergy._value-currentEnergy._value)<100):
        #     m ='     Last pot energy:'+ currentEnergy.__str__()+ " step: {}".format(i+1)
        #     await io.emit("setPositions", {'positions':p, 'message':m})
        #     break

        lastEnergy = currentEnergy
        #print("positions", p[0], p[1], p[2])
        m = '     Current pot energy: {:.3f} kJ/mol - step: {:d}'.format(
            currentEnergy.value_in_unit(unit.kilojoules_per_mole), i + 1)
        #print(m)
        if not (i + 1) % emit_freq:
            await io.emit("setPositions", {
                'positions': p,
                'message': m,
                'step': i
            })
            # io.emit("setPositions", {'positions':p, 'message':m})
            # await io.emit("setEnergy", m)
        #simulation.context.setPositions(complex_structure.positions)

    state = simulation.context.getState(getPositions=True,
                                        getEnergy=True,
                                        getForces=True)
    print('     Final pot energy:', state.getPotentialEnergy())
    print("       in ", time.time() - t0)
    return state
Ejemplo n.º 4
0
    forcefield_kwargs=forcefield_kwargs)

# Use Modeller to combine the protein and ligand into a complex
print('Reading protein')
protein_pdb = PDBFile(pdb_in)

print('Preparing complex')
modeller = Modeller(protein_pdb.topology, protein_pdb.positions)
print('System has %d atoms' % modeller.topology.getNumAtoms())

# This next bit is black magic.
# Modeller needs topology and positions. Lots of trial and error found that this is what works to get these from
# an openforcefield Molecule object that was created from a RDKit molecule.
# The topology part is described in the openforcefield API but the positions part grabs the first (and only)
# conformer and passes it to Modeller. It works. Don't ask why!
modeller.add(ligand_mol.to_topology().to_openmm(), ligand_mol.conformers[0])

print('System has %d atoms' % modeller.topology.getNumAtoms())

# Solvate
print('Adding solvent...')
# we use the 'padding' option to define the periodic box. The PDB file does not contain any
# unit cell information so we just create a box that has a 10A padding around the complex.
modeller.addSolvent(system_generator.forcefield,
                    model='tip3p',
                    padding=10.0 * unit.angstroms)
print('System has %d atoms' % modeller.topology.getNumAtoms())

with open(output_complex, 'w') as outfile:
    PDBFile.writeFile(modeller.topology, modeller.positions, outfile)
Ejemplo n.º 5
0
    print(f'Processing LIG{i}')

    #    try:
    if 1:
        # DO LIGAND THINGS
        try:
            ligand_off_molecule = Molecule(f'{path}/LIG{i}_h.sdf')
        except Exception as e:
            print(e)
            continue
        ligand_pdbfile = PDBFile(f'{path}/LIG{i}_h.pdb')
        force_field = ForceField(
            'openff_unconstrained-1.1.0.offxml'
        )  #smirnoff99Frosst.offxml') #'openff-1.0.0.offxml')
        ligand_system = force_field.create_openmm_system(
            ligand_off_molecule.to_topology())
        ligand_structure = parmed.openmm.load_topology(
            ligand_pdbfile.topology,
            ligand_system,
            xyz=ligand_pdbfile.positions)
    if 1:
        # DO PROTEIN THINGS
        receptor_file = 'receptor.pdb'
        fixed_receptor_file = f'{path}/fixed_receptor.pdb'
        omm_forcefield = app.ForceField('amber14-all.xml')
        fixer = PDBFixer(receptor_file)  #filename='receptor.pdb')
        missingresidues = fixer.findMissingResidues()
        rezez = fixer.findNonstandardResidues()
        fixer.replaceNonstandardResidues()
        fixer.removeHeterogens(keepWater=False)
        missingatoms = fixer.findMissingAtoms()
Ejemplo n.º 6
0
# Use Modeller to combine the protein and ligand into a complex
print('Reading protein')
protein_pdb = PDBFile(opt.receptor)

print('Preparing complex')
modeller = Modeller(protein_pdb.topology, protein_pdb.positions)
print('System has %d atoms' % modeller.topology.getNumAtoms())

# This next bit is black magic.
# Modeller needs topology and positions. Lots of trial and error found that this is what works to get these from
# an openforcefield Molecule object that was created from a RDKit molecule.
# The topology part is described in the openforcefield API but the positions part grabs the first (and only)
# conformer and passes it to Modeller. It works. Don't ask why!
if len(other_mols) != 0:
    for other_mol in other_mols:
        modeller.add(other_mol.to_topology().to_openmm(),
                     other_mol.conformers[0])
    #modeller.add(ligand_mol.to_topology().to_openmm(), ligand_mol.conformers[0])

# Generate ligand with solvent for FEP
if opt.ligand:
    modeller_org = Modeller(ligand_mol.to_topology().to_openmm(),
                            ligand_mol.conformers[0])
    modeller_org.addSolvent(system_generator.forcefield,
                            model='tip3p',
                            ionicStrength=0.1 * unit.molar,
                            padding=10.0 * unit.angstroms)
    system_org = system_generator.create_system(modeller_org.topology,
                                                molecules=ligand_mol)
    system_org.addForce(
        openmm.MonteCarloBarostat(1 * unit.atmospheres, opt.temp * unit.kelvin,