def _generate_parameters(self):
        """
		It generates the parameters of the molecule (from the input_file) as DataLocal in the output folder.
		"""
        import peleffy
        from peleffy.topology import Molecule
        from peleffy.template import Impact
        from peleffy.solvent import OBC2
        from peleffy.main import handle_output_paths
        import os

        # Forcefield and charges method
        forcefield = 'openff_unconstrained-1.2.0.offxml'
        charges_method = 'am1bcc'

        # Create representation of a particular molecule
        PATH_molecule = os.path.join(os.getcwd(), 'output', 'ligand.pdb')
        molecule = Molecule(PATH_molecule)

        # Saving paths
        rotamer_library_output_path, impact_output_path, solvent_output_path = \
         handle_output_paths(molecule = molecule, output =os.path.join(os.getcwd(),'output'), as_datalocal = True )

        # Generate its rotamer library
        rotamer_library = peleffy.topology.RotamerLibrary(molecule)
        rotamer_library.to_file(rotamer_library_output_path)

        # Generate its parameters and template file
        molecule.parameterize(forcefield, charges_method=charges_method)
        impact = Impact(molecule)
        impact.write(impact_output_path)

        # Generate its solvent parameters
        solvent = OBC2(molecule)
        solvent.to_json_file(solvent_output_path)
Exemplo n.º 2
0
    def _generate_parameters(self, smiles, mol_id, output_path,
                             forcefield='openff_unconstrained-1.2.0.offxml',
                             charges_method='am1bcc'):
        """
        It generates the parameters of the molecule (from the input_file)
        as DataLocal in the output folder.

        Parameters
        ----------
        smiles : str
            The smiles tag representing the molecule to minimize
        mol_id : str
            Unique id to identify the molecule to minimize
        output_path : str
            The output path where parameters will be saved
        forcefield : str
            The Open Force Field force field to generate the parameters
            with
        charges_method : str
            The charges method to calculate the partial charges with
        """
        import peleffy
        from peleffy.topology import Molecule
        from peleffy.template import Impact
        from peleffy.solvent import OBC2
        from peleffy.main import handle_output_paths
        import os

        # Create representation of a particular molecule
        molecule = Molecule(smiles=smiles, name=mol_id, tag='UNL')

        # Save molecule to PDB file
        molecule.to_pdb_file(os.path.join(output_path, 'ligand.pdb'))

        # Saving paths
        rotamer_library_output_path, impact_output_path, \
            solvent_output_path = handle_output_paths(molecule=molecule,
                                                      output=output_path,
                                                      as_datalocal=True)

        # Generate its rotamer library
        rotamer_library = peleffy.topology.RotamerLibrary(molecule)
        rotamer_library.to_file(rotamer_library_output_path)

        # Generate its parameters and template file
        molecule.parameterize(forcefield, charges_method=charges_method)
        impact = Impact(molecule)
        impact.write(impact_output_path)

        # Generate its solvent parameters
        solvent = OBC2(molecule)
        solvent.to_json_file(solvent_output_path)
def parallel_run(output_path, solvent, charge_method, pele_exec, pele_src,
                 pele_license, forcefield_name, forcefield, entry):
    """Parallel runner."""

    cid, tag, exp_v = entry

    try:
        molecule = Molecule(smiles=tag, name=cid, tag='LIG')
        if forcefield_name is not None:
            molecule.parameterize(forcefield_name, charge_method=charge_method)
        elif forcefield is not None:
            molecule.set_forcefield(forcefield)
            molecule.parameterize(charge_method=charge_method)

        if ((molecule.forcefield.type == 'OPLS2005')
                or (molecule.forcefield.type == 'OpenFF + OPLS2005'
                    and molecule.forcefield._nonbonding == 'opls2005')):
            if solvent == 'OBC':
                # Generate OBC parameters for OPLS2005
                from peleffy.template import Impact

                os.makedirs(os.path.join(output_path, cid), exist_ok=True)

                impact = Impact(molecule)
                impact.write(os.path.join(output_path, cid, 'ligz'))

                os.makedirs(os.path.join(output_path, cid, 'DataLocal/OBC/'),
                            exist_ok=True)
                os.system('python2 {}scripts/solventOBCParamsGenerator.py '.
                          format(pele_src) +
                          os.path.join(output_path, cid, 'ligz') +
                          ' >> /dev/null')
                shutil.copy(
                    '{}Data/OBC/solventParamsHCTOBC.txt'.format(pele_src),
                    os.path.join(output_path, cid, 'DataLocal/OBC/'))
                os.system('cat ' + os.path.join(
                    output_path, cid, 'ligz_OBCParams.txt >> ' +
                    os.path.join(output_path, cid,
                                 'DataLocal/OBC/solventParamsHCTOBC.txt')))

                os.remove(os.path.join(output_path, cid, 'ligz'))
                os.remove(os.path.join(output_path, cid, 'ligz_OBCParams.txt'))

            forcefield_tag = 'OPLS2005'
        else:
            forcefield_tag = 'OpenForceField'

        # Minimization
        pele_vacuum_min = PELEMinimization(pele_exec,
                                           pele_src,
                                           pele_license,
                                           solvent_type='VACUUM',
                                           output_path=output_path,
                                           forcefield=forcefield_tag)
        pele_vacuum_out = pele_vacuum_min.run(molecule,
                                              output_file='vacuum_out.txt')

        pele_obc_min = PELEMinimization(pele_exec,
                                        pele_src,
                                        pele_license,
                                        solvent_type=solvent,
                                        output_path=output_path,
                                        forcefield=forcefield_tag)
        pele_obc_out = pele_obc_min.run(molecule,
                                        output_file='solvent_out.txt')

        # Calculate energetic difference
        difference = compute_energies(pele_vacuum_out, pele_obc_out)[2]

        return tuple((cid, difference, exp_v))

    except Exception as e:
        print('Exception found with compound {}: '.format(cid) + str(e))