예제 #1
0
def _tester_load_freesolv_gaffmol2_vs_sybylmol2_vs_obabelpdb(
        charge_method="bcc"):
    with utils.enter_temp_directory():

        tar_filename = utils.get_data_filename(
            "chemicals/freesolv/freesolve_v0.3.tar.bz2")
        tar = tarfile.open(tar_filename, mode="r:bz2")
        tar.extractall()
        tar.close()

        database = pickle.load(open("./v0.3/database.pickle"))
        for key in database:
            for directory in ["mol2files_gaff", "mol2files_sybyl"]:
                gaff_filename = os.path.abspath("./v0.3/%s/%s.mol2" %
                                                (directory, key))

                cmd = """sed -i "s/<0>/LIG/" %s""" % gaff_filename
                os.system(
                    cmd
                )  # Have to remove the <0> because it leads to invalid XML in the forcefield files.

                t_gaff = md.load(gaff_filename)

                with utils.enter_temp_directory():
                    yield utils.tag_description(
                        lambda: utils.test_molecule(
                            "LIG", gaff_filename, charge_method=charge_method),
                        "Testing freesolv %s %s with charge model %s" %
                        (directory, key, charge_method))
예제 #2
0
def test_run_antechamber_charges():
    molecule_name = "acetate"
    input_filename = utils.get_data_filename("chemicals/acetate/acetate.mol2")
    with utils.enter_temp_directory():  # Prevents creating tons of GAFF files everywhere.
        gaff_mol2_filename, frcmod_filename = utils.run_antechamber(
            molecule_name, input_filename, charge_method=None, net_charge=-1
        )
예제 #3
0
def test_gromacs_merge():
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    benzene_filename = utils.get_data_filename("chemicals/benzene/benzene.mol2")

    with utils.enter_temp_directory(): #Prevents creating lots of tleap/antechamber files everywhere
        #Generate frcmod files, mol2 files
        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber( "etoh", etoh_filename, charge_method = None)
        gaff_mol2_filename2, frcmod_filename2 = amber.run_antechamber( "benzene", benzene_filename, charge_method = None)

        #Set file names
        prmtop_filename1 = "./out1.prmtop"
        prmtop_filename2 = "./out2.prmtop"
        crd_filename1 = "./out1.inpcrd"
        crd_filename2 = "./out2.inpcrd"
        top_filename1 = "./out1.top"
        top_filename2 = "./out2.top"
        gro_filename1 = "./out1.gro"
        gro_filename2 = "./out2.gro"

        #Generate AMBER files
        amber.run_tleap( 'etoh', gaff_mol2_filename1, frcmod_filename1, prmtop_filename1, crd_filename1 )
        amber.run_tleap( 'benzene', gaff_mol2_filename2, frcmod_filename2, prmtop_filename2, crd_filename2 )

        #Convert to GROMACS
        utils.amber_to_gromacs( "etoh", prmtop_filename1, crd_filename1, out_top = top_filename1, out_gro = gro_filename1 )
        utils.amber_to_gromacs( "benzene", prmtop_filename2, crd_filename2, out_top = top_filename2, out_gro = gro_filename2 )

        #Merge topologies
        gromacs.merge_topologies( [ top_filename1, top_filename2], './combined.top', 'combined', molecule_numbers = [1, 5], molecule_names = ['etoh', 'benzene'] )

        #Test editing of molecule numbers in topology file
        gromacs.change_molecules_section( './combined.top', './edited.top', ['etoh', 'benzene'], [10, 20] )
    def test_InsufficientInit(self):
        with utils.enter_temp_directory():
            #Check wrong number of arguments for adding a component - it requires a name or label at least.
            self.assertRaises(ValueError, self.inst.addComponent, smiles="CC")

            #Check what happens if we don't actually add components
            self.assertRaises(TypeError, self.inst.build )
예제 #5
0
def test_amber_box():
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    trj_list = [md.load(etoh_filename)]

    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.

        box_filename = "./box.pdb"
        box_trj = packmol.pack_box(trj_list, [50])
        box_trj.save(box_filename)

        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber(
            "etoh", etoh_filename, charge_method=None)

        mol2_filenames = [gaff_mol2_filename1]
        frcmod_filenames = [frcmod_filename1]

        prmtop_filename = "./out.prmtop"
        inpcrd_filename = "./out.inpcrd"

        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames,
                                               frcmod_filenames, box_filename,
                                               prmtop_filename,
                                               inpcrd_filename)
        print(tleap_cmd)
예제 #6
0
def test_amber_binary_mixture():
    sustiva_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh_renamed.mol2")

    trj0, trj1 = md.load(sustiva_filename), md.load(etoh_filename)

    # Hack to assign unique residue names that are consistent with contents of mol2 files
    trj0.top.residue(0).name = "LIG"
    trj1.top.residue(0).name = "LI2"

    trj_list = [trj0, trj1]

    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.

        box_filename = "./box.pdb"
        box_trj = packmol.pack_box(trj_list, [25, 50])
        box_trj.save(box_filename)

        gaff_mol2_filename0, frcmod_filename0 = amber.run_antechamber(
            "sustiva", sustiva_filename, charge_method=None)
        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber(
            "etoh", etoh_filename, charge_method=None)

        mol2_filenames = [gaff_mol2_filename0, gaff_mol2_filename1]
        frcmod_filenames = [frcmod_filename0, frcmod_filename1]

        prmtop_filename = "./out.prmtop"
        inpcrd_filename = "./out.inpcrd"

        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames,
                                               frcmod_filenames, box_filename,
                                               prmtop_filename,
                                               inpcrd_filename)
        print(tleap_cmd)
예제 #7
0
def test_run_antechamber_charges():
    molecule_name = "acetate"
    input_filename = utils.get_data_filename("chemicals/acetate/acetate.mol2")
    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(
            molecule_name, input_filename, charge_method=None, net_charge=-1)
예제 #8
0
def test_butanol():
    m0 = openmoltools.openeye.iupac_to_oemol("butanol")
    m1 = openmoltools.openeye.get_charges(m0, keep_confs=-1)
    eq(m0.NumAtoms(), m1.NumAtoms())
    assert m1.NumConfs() >= 2, "Butanol should have multiple conformers."
    assert m1.NumAtoms() == 15, "Butanol should have 15 atoms"
    
    all_data = {}
    for k, molecule in enumerate(m1.GetConfs()):
        names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(molecule)
        all_data[k] = names_to_charges
        eq(sum(names_to_charges.values()), 0.0, decimal=7)  # Net charge should be zero
    
    # Build a table of charges indexed by conformer number and atom name
    all_data = pd.DataFrame(all_data)
    
    # The standard deviation along the conformer axis should be zero if all conformers have same charges
    eq(all_data.std(1).values, np.zeros(m1.NumAtoms()), decimal=7)
    
    with utils.enter_temp_directory():
        # Try saving to disk as mol2
        openmoltools.openeye.molecule_to_mol2(m1, "out.mol2")
        # Make sure MDTraj can read the output
        t = md.load("out.mol2")
        # Make sure MDTraj can read the charges / topology info
        atoms, bonds = md.formats.mol2.mol2_to_dataframes("out.mol2")

        # Finally, make sure MDTraj and OpenEye report the same charges.
        names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(m1)
        q = atoms.set_index("name").charge
        q0 = pd.Series(names_to_charges)
        delta = q - q0  # An object containing the charges, with atom names as indices
        eq(delta.values, np.zeros_like(delta.values), decimal=4)
예제 #9
0
def test_benzene():
    m0 = openmoltools.openeye.iupac_to_oemol("benzene")
    m1 = openmoltools.openeye.get_charges(m0)
    eq(m0.NumAtoms(), m1.NumAtoms())
    print(m1.NumConfs())
    assert m1.NumConfs() == 1, "Benezene should have 1 conformer"
    assert m1.NumAtoms() == 12, "Benezene should have 12 atoms"

    names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(m1)
    eq(sum(names_to_charges.values()), 0.0, decimal=7)  # Net charge should be zero

    with utils.enter_temp_directory():
        # Try saving to disk as mol2
        openmoltools.openeye.molecule_to_mol2(m1, "out.mol2")
        # Make sure MDTraj can read the output
        t = md.load("out.mol2")
        # Make sure MDTraj can read the charges / topology info
        atoms, bonds = md.formats.mol2.mol2_to_dataframes("out.mol2")

        # Finally, make sure MDTraj and OpenEye report the same charges.
        names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(m1)
        q = atoms.set_index("name").charge
        q0 = pd.Series(names_to_charges)
        delta = q - q0  # An object containing the charges, with atom names as indices
        eq(delta.values, np.zeros_like(delta.values), decimal=4)
예제 #10
0
def test_charge_success1():
    with utils.enter_temp_directory():
        openmoltools.openeye.smiles_to_antechamber(
            smiles_fails_with_strictStereo,
            "test.mol2",
            "test.frcmod",
            strictStereo=False)
예제 #11
0
def test_butanol():
    m0 = openmoltools.openeye.iupac_to_oemol("butanol")
    m1 = openmoltools.openeye.get_charges(m0, keep_confs=-1)
    eq(m0.NumAtoms(), m1.NumAtoms())
    assert m1.NumConfs() >= 2, "Butanol should have multiple conformers."
    assert m1.NumAtoms() == 15, "Butanol should have 15 atoms"

    all_data = {}
    for k, molecule in enumerate(m1.GetConfs()):
        names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(molecule)
        all_data[k] = names_to_charges
        eq(sum(names_to_charges.values()), 0.0, decimal=7)  # Net charge should be zero

    # Build a table of charges indexed by conformer number and atom name
    all_data = pd.DataFrame(all_data)

    # The standard deviation along the conformer axis should be zero if all conformers have same charges
    eq(all_data.std(1).values, np.zeros(m1.NumAtoms()), decimal=7)

    with utils.enter_temp_directory():
        # Try saving to disk as mol2
        openmoltools.openeye.molecule_to_mol2(m1, "out.mol2")
        # Make sure MDTraj can read the output
        t = md.load("out.mol2")
        # Make sure MDTraj can read the charges / topology info
        atoms, bonds = md.formats.mol2.mol2_to_dataframes("out.mol2")

        # Finally, make sure MDTraj and OpenEye report the same charges.
        names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(m1)
        q = atoms.set_index("name").charge
        q0 = pd.Series(names_to_charges)
        delta = q - q0  # An object containing the charges, with atom names as indices
        eq(delta.values, np.zeros_like(delta.values), decimal=4)
예제 #12
0
def test_benzene():
    m0 = openmoltools.openeye.iupac_to_oemol("benzene")
    m1 = openmoltools.openeye.get_charges(m0)
    eq(m0.NumAtoms(), m1.NumAtoms())
    print(m1.NumConfs())
    assert m1.NumConfs() == 1, "Benezene should have 1 conformer"
    assert m1.NumAtoms() == 12, "Benezene should have 12 atoms"

    names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(m1)
    eq(sum(names_to_charges.values()), 0.0,
       decimal=7)  # Net charge should be zero

    with utils.enter_temp_directory():
        # Try saving to disk as mol2
        openmoltools.openeye.molecule_to_mol2(m1, "out.mol2")
        # Make sure MDTraj can read the output
        t = md.load("out.mol2")
        # Make sure MDTraj can read the charges / topology info
        atoms, bonds = md.formats.mol2.mol2_to_dataframes("out.mol2")

        # Finally, make sure MDTraj and OpenEye report the same charges.
        names_to_charges, str_repr = openmoltools.openeye.get_names_to_charges(
            m1)
        q = atoms.set_index("name").charge
        q0 = pd.Series(names_to_charges)
        delta = q - q0  # An object containing the charges, with atom names as indices
        eq(delta.values, np.zeros_like(delta.values), decimal=4)
예제 #13
0
def test_acpype_conversion():
    molecule_name = 'sustiva'
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory(): # Prevents creating tons of GAFF files everywhere.
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(molecule_name, input_filename, charge_method=None)
        prmtop, inpcrd = amber.run_tleap(molecule_name, gaff_mol2_filename, frcmod_filename)
        out_top, out_gro = utils.convert_via_acpype( molecule_name, prmtop, inpcrd ) 
예제 #14
0
def _drug_tester(n_molecules=3404, charge_method="bcc"):
    """Helper function for running various versions of the drug parameterization benchmark."""
    assert n_molecules <= 3404, "The maximum number of molecules is 3404."
    assert charge_method in ["bcc", None
                             ], "Charge method must be either None or 'bcc'"

    path = tempfile.mkdtemp()
    database_filename = utils.get_data_filename("chemicals/drugs/Zdd.mol2.gz")
    cmd = "gunzip -c %s > %s/Zdd.mol2" % (database_filename, path)
    os.system(cmd)
    cmd = """awk '/MOLECULE/{close(x);x="%s/molecule_"i++".mol2"}{print > x}' %s/Zdd.mol2""" % (
        path, path)
    os.system(cmd)

    for k in range(n_molecules):
        molecule_name = "molecule_%d" % k
        mol2_filename = "%s/%s.mol2" % (path, molecule_name)
        cmd = """sed -i "s/<0>/LIG/" %s""" % mol2_filename
        os.system(
            cmd
        )  # Have to remove the <0> because it leads to invalid XML in the forcefield files.
        with utils.enter_temp_directory():
            yield utils.tag_description(
                lambda: utils.test_molecule(
                    "LIG", mol2_filename, charge_method=CHARGE_METHOD),
                "Testing drugs %s with charge method %s" %
                (molecule_name, CHARGE_METHOD))
 def test_TypeArgs(self):
     #Check passed input Types
     with utils.enter_temp_directory():
         self.assertRaises(TypeError,self.inst.__init__,[1,'benzene'],['Cc1ccccc1','c1ccccc1'],[3,5],'data/', solute_index=0)
         self.assertRaises(TypeError,self.inst.__init__,['toluene','benzene'],['Cc1ccccc1','c1ccccc1'],[3.5,5],'data/', solute_index=0)
         self.assertRaises(AssertionError,self.inst.__init__,['toluene','benzene'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'test/data/', solute_index=2)
         self.assertRaises(TypeError,self.inst.__init__,['toluene','benzene'],['Cc1ccccc1','c1ccccc1'],[3,5],-3.9, solute_index=0)
예제 #16
0
def test_amber_binary_mixture():
    sustiva_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh_renamed.mol2")

    trj0, trj1 = md.load(sustiva_filename), md.load(etoh_filename)
    
    # Hack to assign unique residue names that are consistent with contents of mol2 files
    trj0.top.residue(0).name = "LIG"
    trj1.top.residue(0).name = "LI2"
    
    trj_list = [trj0, trj1]
    
    with utils.enter_temp_directory():  # Prevents creating tons of GAFF files everywhere.
        
        box_filename = "./box.pdb"
        box_trj = packmol.pack_box(trj_list, [25, 50])
        box_trj.save(box_filename)
        
        gaff_mol2_filename0, frcmod_filename0 = amber.run_antechamber("sustiva", sustiva_filename, charge_method=None)
        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber("etoh", etoh_filename, charge_method=None)
        
        mol2_filenames = [gaff_mol2_filename0, gaff_mol2_filename1]
        frcmod_filenames = [frcmod_filename0, frcmod_filename1]
        
        
        prmtop_filename = "./out.prmtop"
        inpcrd_filename = "./out.inpcrd"

        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames, frcmod_filenames, box_filename, prmtop_filename, inpcrd_filename)
        print(tleap_cmd)
예제 #17
0
def test_gromacs_merge():
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    benzene_filename = utils.get_data_filename("chemicals/benzene/benzene.mol2")

    with utils.enter_temp_directory(): #Prevents creating lots of tleap/antechamber files everywhere
        #Generate frcmod files, mol2 files
        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber( "etoh", etoh_filename, charge_method = None)
        gaff_mol2_filename2, frcmod_filename2 = amber.run_antechamber( "benzene", benzene_filename, charge_method = None)

        #Set file names
        prmtop_filename1 = "./out1.prmtop"
        prmtop_filename2 = "./out2.prmtop"
        crd_filename1 = "./out1.inpcrd"
        crd_filename2 = "./out2.inpcrd"
        top_filename1 = "./out1.top"
        top_filename2 = "./out2.top"
        gro_filename1 = "./out1.gro"
        gro_filename2 = "./out2.gro"

        #Generate AMBER files
        amber.run_tleap( 'etoh', gaff_mol2_filename1, frcmod_filename1, prmtop_filename1, crd_filename1 )
        amber.run_tleap( 'benzene', gaff_mol2_filename2, frcmod_filename2, prmtop_filename2, crd_filename2 )

        #Convert to GROMACS
        utils.convert_via_acpype( "etoh", prmtop_filename1, crd_filename1, out_top = top_filename1, out_gro = gro_filename1 ) 
        utils.convert_via_acpype( "benzene", prmtop_filename2, crd_filename2, out_top = top_filename2, out_gro = gro_filename2 )

        #Merge topologies
        gromacs.merge_topologies( [ top_filename1, top_filename2], './combined.top', 'combined', molecule_numbers = [1, 5], molecule_names = ['etoh', 'benzene'] )

        #Test editing of molecule numbers in topology file
        gromacs.change_molecules_section( './combined.top', './edited.top', ['etoh', 'benzene'], [10, 20] )
예제 #18
0
def test_ffxml():
    with utils.enter_temp_directory():    
        m0 = openmoltools.openeye.smiles_to_oemol("CCCCO")
        charged0 = openmoltools.openeye.get_charges(m0)
        m1 = openmoltools.openeye.smiles_to_oemol("ClC(Cl)(Cl)Cl")
        charged1 = openmoltools.openeye.get_charges(m1)

        trajectories, ffxml = openmoltools.openeye.oemols_to_ffxml([charged0, charged1])
예제 #19
0
def test_run_antechamber_resname():
    molecule_name = "sustiva"
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory():  # Prevents creating tons of GAFF files everywhere.
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(molecule_name, input_filename, charge_method=None, resname=True)
        with open(gaff_mol2_filename, 'r') as fin:
            fin.readline()
            assert fin.readline().strip() == molecule_name
예제 #20
0
def test_drugs():
    import openeye.oechem
    database_filename = utils.get_data_filename("chemicals/drugs/Zdd.mol2.gz")
    ifs = openeye.oechem.oemolistream(database_filename)
    for molecule in ifs.GetOEMols():
        with utils.enter_temp_directory():
            molecule_name, tripos_mol2_filename = utils.molecule_to_mol2(molecule)
            yield utils.tag_description(lambda : utils.test_molecule(molecule_name, tripos_mol2_filename), "Testing drugs %s" % molecule_name)
 def test_build_monomers(self):
     with utils.enter_temp_directory():
         #Check smile strings
         self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['smile_error','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'data/', solute_index=2)
         self.assertRaises(ValueError,self.inst.build_monomers)
         #Check IO Errors
         self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'/', solute_index=2)
         self.assertRaises(IOError,self.inst.build_monomers)
예제 #22
0
def test_ffxml():
    with utils.enter_temp_directory():
        m0 = openmoltools.openeye.smiles_to_oemol("CCCCO")
        charged0 = openmoltools.openeye.get_charges(m0)
        m1 = openmoltools.openeye.smiles_to_oemol("ClC(Cl)(Cl)Cl")
        charged1 = openmoltools.openeye.get_charges(m1)

        trajectories, ffxml = openmoltools.openeye.oemols_to_ffxml([charged0, charged1])
예제 #23
0
def test_charge_fail1():
    with assert_raises(RuntimeError):
        with utils.enter_temp_directory():
            openmoltools.openeye.smiles_to_antechamber(
                smiles_fails_with_strictStereo,
                "test.mol2",
                "test.frcmod",
                strictStereo=True)
 def test_build_boxes(self):
     #Check IO Errors
     with utils.enter_temp_directory():
         self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'/',solute_index=2)
         self.assertRaises(IOError,self.inst.build_boxes)
         self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'test/data/',solute_index=2)
         self.inst.inpcrd_filename = 'inpcrd_filename' 
         self.inst.prmtop_filename = 'prmtop_filename'
         self.assertRaises(IOError,self.inst.build_boxes)
예제 #25
0
def test_run_tleap():
    molecule_name = "sustiva"
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(
            molecule_name, input_filename, charge_method=None)
        prmtop, inpcrd = amber.run_tleap(molecule_name, gaff_mol2_filename,
                                         frcmod_filename)
예제 #26
0
def smiles_to_antechamber(smiles_string,
                          gaff_mol2_filename,
                          frcmod_filename,
                          residue_name="MOL",
                          strictStereo=False,
                          protonation=False):
    """Build a molecule from a smiles string and run antechamber,
    generating GAFF mol2 and frcmod files from a smiles string.  Charges
    will be generated using the OpenEye QuacPac AM1-BCC implementation.

    Parameters
    ----------
    smiles_string : str
        Smiles string of molecule to construct and charge
    gaff_mol2_filename : str
        Filename of mol2 file output of antechamber, with charges
        created from openeye
    frcmod_filename : str
        Filename of frcmod file output of antechamber.  Most likely
        this file will be almost empty, at least for typical molecules.
    residue_name : str, optional, default="MOL"
        OpenEye writes mol2 files with <0> as the residue / ligand name.
        This chokes many mol2 parsers, so we replace it with a string of
        your choosing.  This might be useful for downstream applications
        if the residue names are required to be unique.
    strictStereo : bool, optional, default=False
        If False, permits smiles strings with unspecified stereochemistry.
        See https://docs.eyesopen.com/omega/usage.html
    protonation : bool, optional, default=False
        If True, uses OESetNeutralpHModel to set a pH model for the molecule
        to attempt to obtain protonation states appropriate for neutral pH.
        Depending on the application this may or may not be what you want, e.g. for
        hydration free energy calculations you may want the typical depicted (neutral) form.
    """
    oechem = import_("openeye.oechem")
    if not oechem.OEChemIsLicensed():
        raise (ImportError("Need License for oechem!"))
    oequacpac = import_("openeye.oequacpac")

    # Get the absolute path so we can find these filenames from inside a temporary directory.
    gaff_mol2_filename = os.path.abspath(gaff_mol2_filename)
    frcmod_filename = os.path.abspath(frcmod_filename)

    m = smiles_to_oemol(smiles_string)
    if protonation:
        oequacpac.OESetNeutralpHModel(m)
    m = get_charges(m, strictStereo=strictStereo, keep_confs=1)

    with enter_temp_directory(
    ):  # Avoid dumping 50 antechamber files in local directory.
        _unused = molecule_to_mol2(m, "./tmp.mol2", residue_name=residue_name)
        net_charge = oechem.OENetCharge(m)
        tmp_gaff_mol2_filename, tmp_frcmod_filename = run_antechamber(
            "tmp", "./tmp.mol2", charge_method=None,
            net_charge=net_charge)  # USE OE AM1BCC charges!
        shutil.copy(tmp_gaff_mol2_filename, gaff_mol2_filename)
        shutil.copy(tmp_frcmod_filename, frcmod_filename)
예제 #27
0
def test_common_molecules():
    import openeye.oechem
    for molecule_name in molecules:
        molecule = openmoltools.openeye.iupac_to_oemol(molecule_name)
        molecule = openmoltools.openeye.get_charges(molecule)
        with utils.enter_temp_directory():
            tripos_mol2_filename = 'molecule.mol2'
            molecule_name, tripos_mol2_filename = utils.molecule_to_mol2(molecule, tripos_mol2_filename=tripos_mol2_filename)
            yield utils.tag_description(lambda : utils.test_molecule('molecule', tripos_mol2_filename), "Testing molecule %s" % molecule_name)
예제 #28
0
def test_run_antechamber_resname():
    molecule_name = "sustiva"
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(
            molecule_name, input_filename, charge_method=None, resname=True)
        with open(gaff_mol2_filename, 'r') as fin:
            fin.readline()
            assert fin.readline().strip() == molecule_name
 def test_ChemParsing(self):
     with utils.enter_temp_directory():
         self.inst = MixtureSystem()
         #Try passing invalid SMILES
         self.assertRaises( ValueError, self.inst.addComponent, name='phenol', smiles='smiles')
         #Try building with an invalid solute_index
         self.inst = MixtureSystem()
         self.inst.addComponent('toluene')
         self.assertRaises( AssertionError, self.inst.build, gromacs = True,
             solute_index = 2)
예제 #30
0
def test_acpype_conversion():
    molecule_name = 'sustiva'
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(
            molecule_name, input_filename, charge_method=None)
        prmtop, inpcrd = amber.run_tleap(molecule_name, gaff_mol2_filename,
                                         frcmod_filename)
        out_top, out_gro = utils.convert_via_acpype(molecule_name, prmtop,
                                                    inpcrd)
예제 #31
0
def test_ffxml_simulation():
    """Test converting toluene and benzene smiles to oemol to ffxml to openmm simulation."""
    with utils.enter_temp_directory():
        m0 = openmoltools.openeye.smiles_to_oemol("Cc1ccccc1")
        charged0 = openmoltools.openeye.get_charges(m0)
        m1 = openmoltools.openeye.smiles_to_oemol("c1ccccc1")
        charged1 = openmoltools.openeye.get_charges(m1)
        ligands = [charged0, charged1]
        n_atoms = [15,12]

        trajectories, ffxml = openmoltools.openeye.oemols_to_ffxml(ligands)
        eq(len(trajectories),len(ligands))

        pdb_filename = utils.get_data_filename("chemicals/proteins/1vii.pdb")

        temperature = 300 * u.kelvin
        friction = 0.3 / u.picosecond
        timestep = 0.01 * u.femtosecond

        protein_traj = md.load(pdb_filename)
        protein_traj.center_coordinates()

        protein_top = protein_traj.top.to_openmm()
        protein_xyz = protein_traj.openmm_positions(0)

        for k, ligand in enumerate(ligands):
            ligand_traj = trajectories[k]
            ligand_traj.center_coordinates()

            eq(ligand_traj.n_atoms, n_atoms[k])
            eq(ligand_traj.n_frames, 1)

            #Move the pre-centered ligand sufficiently far away from the protein to avoid a clash.
            min_atom_pair_distance = ((ligand_traj.xyz[0] ** 2.).sum(1) ** 0.5).max() + ((protein_traj.xyz[0] ** 2.).sum(1) ** 0.5).max() + 0.3
            ligand_traj.xyz += np.array([1.0, 0.0, 0.0]) * min_atom_pair_distance

            ligand_xyz = ligand_traj.openmm_positions(0)
            ligand_top = ligand_traj.top.to_openmm()

            ffxml.seek(0)
            forcefield = app.ForceField("amber10.xml", ffxml, "tip3p.xml")

            model = app.modeller.Modeller(protein_top, protein_xyz)
            model.add(ligand_top, ligand_xyz)
            model.addSolvent(forcefield, padding=0.4 * u.nanometer)

            system = forcefield.createSystem(model.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HAngles)

            integrator = mm.LangevinIntegrator(temperature, friction, timestep)

            simulation = app.Simulation(model.topology, system, integrator)
            simulation.context.setPositions(model.positions)
            print("running")
            simulation.step(1)
예제 #32
0
def test_ffxml_simulation():
    """Test converting toluene and benzene smiles to oemol to ffxml to openmm simulation."""
    with utils.enter_temp_directory():    
        m0 = openmoltools.openeye.smiles_to_oemol("Cc1ccccc1")
        charged0 = openmoltools.openeye.get_charges(m0)
        m1 = openmoltools.openeye.smiles_to_oemol("c1ccccc1")
        charged1 = openmoltools.openeye.get_charges(m1)
        ligands = [charged0, charged1]
        n_atoms = [15,12]

        trajectories, ffxml = openmoltools.openeye.oemols_to_ffxml(ligands)
        eq(len(trajectories),len(ligands))

        pdb_filename = utils.get_data_filename("chemicals/proteins/1vii.pdb")

        temperature = 300 * u.kelvin
        friction = 0.3 / u.picosecond
        timestep = 0.01 * u.femtosecond

        protein_traj = md.load(pdb_filename)
        protein_traj.center_coordinates()

        protein_top = protein_traj.top.to_openmm()
        protein_xyz = protein_traj.openmm_positions(0)

        for k, ligand in enumerate(ligands):
            ligand_traj = trajectories[k]
            ligand_traj.center_coordinates()
        
            eq(ligand_traj.n_atoms, n_atoms[k])
            eq(ligand_traj.n_frames, 1)

            #Move the pre-centered ligand sufficiently far away from the protein to avoid a clash.  
            min_atom_pair_distance = ((ligand_traj.xyz[0] ** 2.).sum(1) ** 0.5).max() + ((protein_traj.xyz[0] ** 2.).sum(1) ** 0.5).max() + 0.3
            ligand_traj.xyz += np.array([1.0, 0.0, 0.0]) * min_atom_pair_distance

            ligand_xyz = ligand_traj.openmm_positions(0)
            ligand_top = ligand_traj.top.to_openmm()

            ffxml.seek(0)
            forcefield = app.ForceField("amber10.xml", ffxml, "tip3p.xml")

            model = app.modeller.Modeller(protein_top, protein_xyz)
            model.add(ligand_top, ligand_xyz)
            model.addSolvent(forcefield, padding=0.4 * u.nanometer)

            system = forcefield.createSystem(model.topology, nonbondedMethod=app.PME, nonbondedCutoff=1.0 * u.nanometers, constraints=app.HAngles)

            integrator = mm.LangevinIntegrator(temperature, friction, timestep)

            simulation = app.Simulation(model.topology, system, integrator)
            simulation.context.setPositions(model.positions)
            print("running")
            simulation.step(1)
예제 #33
0
def test_gromacs_solvate():
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    with utils.enter_temp_directory(): #Prevents creating lots of tleap/antechamber files everywhere
        #Generate frcmod files, mol2 files
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber( "etoh", etoh_filename, charge_method = None)

        #Amber setup
        amber.run_tleap( 'etoh', gaff_mol2_filename, frcmod_filename, 'etoh.prmtop', 'etoh.crd' )
        #GROMACS conversion
        utils.amber_to_gromacs( 'etoh', 'etoh.prmtop', 'etoh.crd', 'etoh.top', 'etoh.gro' )
        #Solvate
        gromacs.do_solvate( 'etoh.top', 'etoh.gro', 'etoh_solvated.top', 'etoh_solvated.gro', 1.2, 'dodecahedron', 'spc216', 'tip3p.itp' )
예제 #34
0
def test_drugs():
    import openeye.oechem
    database_filename = utils.get_data_filename("chemicals/drugs/Zdd.mol2.gz")
    ifs = openeye.oechem.oemolistream(database_filename)
    for molecule in ifs.GetOEMols():
        with utils.enter_temp_directory():
            molecule_name, tripos_mol2_filename = utils.molecule_to_mol2(
                molecule)
            yield utils.tag_description(
                lambda: utils.test_molecule(molecule_name, tripos_mol2_filename
                                            ),
                "Testing drugs %s" % molecule_name)
예제 #35
0
def test_gromacs_solvate():
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    with utils.enter_temp_directory(): #Prevents creating lots of tleap/antechamber files everywhere
        #Generate frcmod files, mol2 files
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber( "etoh", etoh_filename, charge_method = None)

        #Amber setup
        amber.run_tleap( 'etoh', gaff_mol2_filename, frcmod_filename, 'etoh.prmtop', 'etoh.crd' )
        #GROMACS conversion
        utils.convert_via_acpype( 'etoh', 'etoh.prmtop', 'etoh.crd', 'etoh.top', 'etoh.gro' )
        #Solvate
        gromacs.do_solvate( 'etoh.top', 'etoh.gro', 'etoh_solvated.top', 'etoh_solvated.gro', 1.2, 'dodecahedron', 'spc216', 'tip3p.itp' )
예제 #36
0
def _tester_load_freesolv_gaffmol2_vs_sybylmol2_vs_obabelpdb(charge_method="bcc"):
    with utils.enter_temp_directory():

        tar_filename = utils.get_data_filename("chemicals/freesolv/freesolve_v0.3.tar.bz2")
        tar = tarfile.open(tar_filename, mode="r:bz2")
        tar.extractall()
        tar.close()

        database = pickle.load(open("./v0.3/database.pickle"))
        for key in database:
            for directory in ["mol2files_gaff", "mol2files_sybyl"]:
                gaff_filename = os.path.abspath("./v0.3/%s/%s.mol2" % (directory, key))

                cmd = """sed -i "s/<0>/LIG/" %s""" % gaff_filename
                os.system(cmd)  # Have to remove the <0> because it leads to invalid XML in the forcefield files.

                t_gaff = md.load(gaff_filename)

                with utils.enter_temp_directory():
                    yield utils.tag_description(
                        lambda: utils.test_molecule("LIG", gaff_filename, charge_method=charge_method),
                        "Testing freesolv %s %s with charge model %s" % (directory, key, charge_method),
                    )
예제 #37
0
def smiles_to_antechamber(smiles_string, gaff_mol2_filename, frcmod_filename, residue_name="MOL", strictStereo=False, protonation=False):
    """Build a molecule from a smiles string and run antechamber,
    generating GAFF mol2 and frcmod files from a smiles string.  Charges
    will be generated using the OpenEye QuacPac AM1-BCC implementation.

    Parameters
    ----------
    smiles_string : str
        Smiles string of molecule to construct and charge
    gaff_mol2_filename : str
        Filename of mol2 file output of antechamber, with charges
        created from openeye
    frcmod_filename : str
        Filename of frcmod file output of antechamber.  Most likely
        this file will be almost empty, at least for typical molecules.
    residue_name : str, optional, default="MOL"
        OpenEye writes mol2 files with <0> as the residue / ligand name.
        This chokes many mol2 parsers, so we replace it with a string of
        your choosing.  This might be useful for downstream applications
        if the residue names are required to be unique.
    strictStereo : bool, optional, default=False
        If False, permits smiles strings with unspecified stereochemistry.
        See https://docs.eyesopen.com/omega/usage.html
    protonation : bool, optional, default=False
        If True, uses OESetNeutralpHModel to set a pH model for the molecule
        to attempt to obtain protonation states appropriate for neutral pH.
        Depending on the application this may or may not be what you want, e.g. for
        hydration free energy calculations you may want the typical depicted (neutral) form.
    """
    oechem = import_("openeye.oechem")
    if not oechem.OEChemIsLicensed(): raise(ImportError("Need License for oechem!"))
    oequacpac = import_("openeye.oequacpac")

    # Get the absolute path so we can find these filenames from inside a temporary directory.
    gaff_mol2_filename = os.path.abspath(gaff_mol2_filename)
    frcmod_filename = os.path.abspath(frcmod_filename)

    m = smiles_to_oemol(smiles_string)
    if protonation:
        oequacpac.OESetNeutralpHModel(m)
    m = get_charges(m, strictStereo=strictStereo, keep_confs=1)

    with enter_temp_directory():  # Avoid dumping 50 antechamber files in local directory.
        _unused = molecule_to_mol2(m, "./tmp.mol2", residue_name=residue_name)
        net_charge = oechem.OENetCharge(m)
        tmp_gaff_mol2_filename, tmp_frcmod_filename = run_antechamber("tmp", "./tmp.mol2", charge_method=None, net_charge=net_charge)  # USE OE AM1BCC charges!
        shutil.copy(tmp_gaff_mol2_filename, gaff_mol2_filename)
        shutil.copy(tmp_frcmod_filename, frcmod_filename)
예제 #38
0
def test_parmed_conversion():
    molecule_name = 'sustiva'
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        #Make sure conversion runs
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(
            molecule_name, input_filename, charge_method=None)
        prmtop, inpcrd = amber.run_tleap(molecule_name, gaff_mol2_filename,
                                         frcmod_filename)
        out_top, out_gro = utils.amber_to_gromacs(molecule_name,
                                                  prmtop,
                                                  inpcrd,
                                                  precision=8)

        #Test energies before and after conversion
        #Set up amber system
        a = parmed.amber.AmberParm(prmtop, inpcrd)
        ambersys = a.createSystem()
        ambercon = mmmm.Context(ambersys, mm.VerletIntegrator(0.001))
        ambercon.setPositions(a.positions)
        #Set up GROMACS system
        g = parmed.load_file(out_top)
        gro = parmed.gromacs.GromacsGroFile.parse(out_gro)
        g.box = gro.box
        g.positions = gro.positions
        gromacssys = g.createSystem()
        gromacscon = mmmm.Context(gromacssys, mm.VerletIntegrator(0.001))
        gromacscon.setPositions(g.positions)

        #Check energies
        a_energies = parmed.openmm.utils.energy_decomposition(a, ambercon)
        g_energies = parmed.openmm.utils.energy_decomposition(g, gromacscon)
        #Check components
        tolerance = 1e-5
        ok = True
        for key in a_energies.keys():
            diff = np.abs(a_energies[key] - g_energies[key])
            if diff / np.abs(a_energies[key]) > tolerance:
                ok = False
                print(
                    "In testing AMBER to GROMACS conversion, %s energy differs by %.5g, which is more than a fraction %.2g of the total, so conversion appears not to be working properly."
                    % (key, diff, tolerance))
        if not ok:
            raise (ValueError(
                "AMBER to GROMACS conversion yields energies which are too different."
            ))
예제 #39
0
def test_binary_mixture_rename():
    smiles_string0 = "CCCCCC"
    smiles_string1 = "CCCCCCCCC"

    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        mol2_filename0 = "./A.mol2"
        frcmod_filename0 = "./A.frcmod"

        mol2_filename1 = "./B.mol2"
        frcmod_filename1 = "./B.frcmod"

        gaff_mol2_filenames = [mol2_filename0, mol2_filename1]
        frcmod_filenames = [frcmod_filename0, frcmod_filename1]

        prmtop_filename = "./box.prmtop"
        inpcrd_filename = "./box.inpcrd"

        openmoltools.openeye.smiles_to_antechamber(smiles_string0,
                                                   mol2_filename0,
                                                   frcmod_filename0)
        openmoltools.openeye.smiles_to_antechamber(smiles_string1,
                                                   mol2_filename1,
                                                   frcmod_filename1)

        openmoltools.utils.randomize_mol2_residue_names(gaff_mol2_filenames)

        box_pdb_filename = "./box.pdb"

        gaff_mol2_filenames = [mol2_filename0, mol2_filename1]
        n_monomers = [10, 20]

        packed_trj = packmol.pack_box(
            [md.load(mol2) for mol2 in gaff_mol2_filenames], n_monomers)
        packed_trj.save(box_pdb_filename)

        tleap_cmd = openmoltools.amber.build_mixture_prmtop(
            gaff_mol2_filenames, frcmod_filenames, box_pdb_filename,
            prmtop_filename, inpcrd_filename)

        prmtop = app.AmberPrmtopFile(prmtop_filename)
        inpcrd = app.AmberInpcrdFile(inpcrd_filename)

        system = prmtop.createSystem(nonbondedMethod=app.PME,
                                     nonbondedCutoff=1.0 * u.nanometers,
                                     constraints=app.HBonds)
예제 #40
0
def test_amber_water_mixture():
    water_filename = utils.get_data_filename("chemicals/water/water.mol2")
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    sustiva_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")

    with utils.enter_temp_directory():  # Prevents creating tons of GAFF files everywhere.
        shutil.copy( water_filename, 'c1.mol2' )
        shutil.copy( etoh_filename, 'c2.mol2' )
        shutil.copy( sustiva_filename, 'c3.mol2')
        water_filename = 'c1.mol2'
        etoh_filename = 'c2.mol2'
        sustiva_filename = 'c3.mol2'
        #Randomize residue names to avoid clashes
        utils.randomize_mol2_residue_names( [ water_filename, etoh_filename, sustiva_filename] )

        trj0, trj1, trj2 = md.load(water_filename), md.load(etoh_filename), md.load(sustiva_filename)

        trj_list = [trj0, trj1, trj2]
        
        box_filename = "./box.pdb"
        box_trj = packmol.pack_box(trj_list, [300, 25, 3])
        box_trj.save(box_filename)
        
        gaff_mol2_filename0, frcmod_filename0 = amber.run_antechamber("water", water_filename, charge_method=None)
        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber("etoh", etoh_filename, charge_method=None)
        gaff_mol2_filename2, frcmod_filename2 = amber.run_antechamber("sustiva", sustiva_filename, charge_method=None)
        
        mol2_filenames = [gaff_mol2_filename0, gaff_mol2_filename1, gaff_mol2_filename2]
        frcmod_filenames = [frcmod_filename0, frcmod_filename1, frcmod_filename2]
        
        
        prmtop_filename = "./out.prmtop"
        inpcrd_filename = "./out.inpcrd"

        shutil.copy(box_filename, 'renamed.pdb')
        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames, frcmod_filenames, 'renamed.pdb', prmtop_filename, inpcrd_filename)
        print(tleap_cmd)

        #Also do here for case of GAFF water
        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames, frcmod_filenames, box_filename, prmtop_filename, inpcrd_filename, water_model = None)
        print(tleap_cmd)

        #Also do here for case of SPC
        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames, frcmod_filenames, 'renamed.pdb', prmtop_filename, inpcrd_filename, water_model = 'SPC')
        print(tleap_cmd)
 def test_convert_to_gromacs(self):
         #Check coversion by using a wrong directory
         self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'/', solute_index=2)
         self.assertRaises(IOError,self.inst.convert_to_gromacs)
         #Check merge_topologies by using wrong filenames (solute_index=None case)
         with utils.enter_temp_directory():
            self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'test/data/', solute_index=None)
            self.inst.top_filenames = ['test/data/Error_filenames']
            self.inst.top_filename = 'test/data/Error_filename'
            self.assertRaises(IOError,self.inst.convert_to_gromacs)
            #Check solute_index is in the correct range
            self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,5,80,7],'test/data/', solute_index=6)
            self.assertRaises(IOError,self.inst.convert_to_gromacs)
            #Check merge_topologies by using wrong filenames (solute_index='auto' case)
            self.inst = MixtureSystem(['toluene','benzene','cyclohexane','ethane'],['Cc1ccccc1','c1ccccc1','C1CCCCC1','CC'],[3,1,80,7],'test/data/', solute_index='auto')
            self.inst.top_filenames = ['test/data/Error_filenames']
            self.inst.top_filename = 'test/data/Error_filename'
            self.assertRaises(IOError,self.inst.convert_to_gromacs)
예제 #42
0
def _drug_tester(n_molecules=3404, charge_method="bcc"):
    """Helper function for running various versions of the drug parameterization benchmark."""
    assert n_molecules <= 3404, "The maximum number of molecules is 3404."
    assert charge_method in ["bcc", None], "Charge method must be either None or 'bcc'"

    path = tempfile.mkdtemp()
    database_filename = utils.get_data_filename("chemicals/drugs/Zdd.mol2.gz")
    cmd = "gunzip -c %s > %s/Zdd.mol2" % (database_filename, path)
    os.system(cmd)
    cmd = """awk '/MOLECULE/{close(x);x="%s/molecule_"i++".mol2"}{print > x}' %s/Zdd.mol2""" % (path, path)
    os.system(cmd)

    for k in range(n_molecules):
        molecule_name = "molecule_%d" % k
        mol2_filename = "%s/%s.mol2" % (path, molecule_name)
        cmd = """sed -i "s/<0>/LIG/" %s""" % mol2_filename
        os.system(cmd)  # Have to remove the <0> because it leads to invalid XML in the forcefield files.
        with utils.enter_temp_directory():
            yield utils.tag_description(lambda : utils.test_molecule("LIG", mol2_filename, charge_method=CHARGE_METHOD), "Testing drugs %s with charge method %s" % (molecule_name, CHARGE_METHOD))
    def test_TypeArgs(self):
        #Check passed input Types
        with utils.enter_temp_directory():

            #Add a component with an integer name to ensure we catch
            self.inst = MixtureSystem()
            self.assertRaises(ValueError, self.inst.addComponent, name=1 )

            #Add a non-integer number of molecules to ensure we catch
            self.assertRaises(ValueError, self.inst.addComponent, name='phenol', number=3.5)

            #Add an invalid mole fraction
            self.assertRaises(ValueError, self.inst.addComponent, name='phenol', mole_fraction=1.2 )            
            self.assertRaises(ValueError, self.inst.addComponent, name='phenol', mole_fraction=-0.2 )            
            
            #Add mole fractions totaling greater than 1, check that we catch
            self.inst.addComponent('phenol', mole_fraction = 0.9)
            self.inst.addComponent('toluene', mole_fraction = 0.2)
            self.assertRaises( ValueError, self.inst.build )
예제 #44
0
def oemol_to_antechamber(m, gaff_mol2_filename, frcmod_filename, residue_name="MOL", strictStereo=False):
    """
        Build a molecule from a mol2 file and run antechamber,
        generating GAFF mol2 and frcmod files from a smiles string.  Charges
        will be generated using the OpenEye QuacPac AM1-BCC implementation.
        
        Created by hacking openmoltools/openeye.py
        
        Parameters
        ----------
        m : oechem molecule object
        Molecule to construct and charge
        gaff_mol2_filename : str
        Filename of mol2 file output of antechamber, with charges
        created from openeye
        frcmod_filename : str
        Filename of frcmod file output of antechamber.  Most likely
        this file will be almost empty, at least for typical molecules.
        residue_name : str, optional, default="MOL"
        
        OpenEye writes mol2 files with <0> as the residue / ligand name.
        This chokes many mol2 parsers, so we replace it with a string of
        your choosing.  This might be useful for downstream applications
        if the residue names are required to be unique.
        strictStereo : bool, optional, default=False
        If False, permits smiles strings with unspecified stereochemistry.
        See https://docs.eyesopen.com/omega/usage.html
    """
    #oechem = import_("openeye.oechem")
    #if not oechem.OEChemIsLicensed(): raise(ImportError("Need License for oechem!"))
    
    # Get the absolute path so we can find these filenames from inside a temporary directory.
    gaff_mol2_filename = os.path.abspath(gaff_mol2_filename)
    frcmod_filename = os.path.abspath(frcmod_filename)
    
    m = openeye.get_charges(m, strictStereo=strictStereo, keep_confs=1)
    
    with enter_temp_directory():  # Avoid dumping 50 antechamber files in local directory.
        _unused = openeye.molecule_to_mol2(m, "./tmp.mol2", residue_name=residue_name)
        net_charge = oechem.OENetCharge(m)
        tmp_gaff_mol2_filename, tmp_frcmod_filename = amber.run_antechamber("tmp", "./tmp.mol2", charge_method=None, net_charge=net_charge)  # USE OE AM1BCC charges!
        shutil.copy(tmp_gaff_mol2_filename, gaff_mol2_filename)
        shutil.copy(tmp_frcmod_filename, frcmod_filename)
예제 #45
0
def test_amber_box():
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    trj_list = [md.load(etoh_filename)]
    
    with utils.enter_temp_directory():  # Prevents creating tons of GAFF files everywhere.
        
        box_filename = "./box.pdb"
        box_trj = packmol.pack_box(trj_list, [50])
        box_trj.save(box_filename)
    
        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber("etoh", etoh_filename, charge_method=None)
        
        mol2_filenames = [gaff_mol2_filename1]
        frcmod_filenames =  [frcmod_filename1]
        
        prmtop_filename = "./out.prmtop"
        inpcrd_filename = "./out.inpcrd"

        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames, frcmod_filenames, box_filename, prmtop_filename, inpcrd_filename)
        print(tleap_cmd)
예제 #46
0
def test_parmed_conversion():
    molecule_name = 'sustiva'
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory(): # Prevents creating tons of GAFF files everywhere.
        #Make sure conversion runs
        gaff_mol2_filename, frcmod_filename = amber.run_antechamber(molecule_name, input_filename, charge_method=None)
        prmtop, inpcrd = amber.run_tleap(molecule_name, gaff_mol2_filename, frcmod_filename)
        out_top, out_gro = utils.amber_to_gromacs( molecule_name, prmtop, inpcrd, precision = 8 ) 

        #Test energies before and after conversion
        #Set up amber system
        a = parmed.amber.AmberParm( prmtop, inpcrd )
        ambersys = a.createSystem()
        ambercon = mmmm.Context( ambersys, mm.VerletIntegrator(0.001))
        ambercon.setPositions( a.positions )
        #Set up GROMACS system
        g = parmed.load_file( out_top )
        gro = parmed.gromacs.GromacsGroFile.parse( out_gro ) 
        g.box = gro.box
        g.positions = gro.positions
        gromacssys = g.createSystem()
        gromacscon = mmmm.Context( gromacssys, mm.VerletIntegrator(0.001))
        gromacscon.setPositions( g.positions ) 

        #Check energies
        a_energies = parmed.openmm.utils.energy_decomposition( a, ambercon )    
        g_energies = parmed.openmm.utils.energy_decomposition( g, gromacscon )
        #Check components
        tolerance = 1e-5
        ok = True
        for key in a_energies.keys():
            diff = np.abs(a_energies[key] - g_energies[key] )
            if diff/np.abs(a_energies[key]) > tolerance:
                ok = False
                print("In testing AMBER to GROMACS conversion, %s energy differs by %.5g, which is more than a fraction %.2g of the total, so conversion appears not to be working properly." % ( key, diff, tolerance) )
        if not ok:
            raise(ValueError("AMBER to GROMACS conversion yields energies which are too different.")) 
예제 #47
0
def test_binary_mixture_rename():
    smiles_string0 = "CCCCCC"
    smiles_string1 = "CCCCCCCCC"

    with utils.enter_temp_directory():  # Prevents creating tons of GAFF files everywhere.
        mol2_filename0 = "./A.mol2"
        frcmod_filename0 = "./A.frcmod"

        mol2_filename1 = "./B.mol2"
        frcmod_filename1 = "./B.frcmod"

        gaff_mol2_filenames = [mol2_filename0, mol2_filename1]
        frcmod_filenames = [frcmod_filename0, frcmod_filename1]

        prmtop_filename = "./box.prmtop"
        inpcrd_filename = "./box.inpcrd"

        openmoltools.openeye.smiles_to_antechamber(smiles_string0, mol2_filename0, frcmod_filename0)
        openmoltools.openeye.smiles_to_antechamber(smiles_string1, mol2_filename1, frcmod_filename1)

        openmoltools.utils.randomize_mol2_residue_names(gaff_mol2_filenames)

        box_pdb_filename = "./box.pdb"

        gaff_mol2_filenames = [mol2_filename0, mol2_filename1]
        n_monomers = [10, 20]

        packed_trj = packmol.pack_box([md.load(mol2) for mol2 in gaff_mol2_filenames], n_monomers)
        packed_trj.save(box_pdb_filename)

        tleap_cmd = openmoltools.amber.build_mixture_prmtop(gaff_mol2_filenames, frcmod_filenames, box_pdb_filename, prmtop_filename, inpcrd_filename)

        prmtop = app.AmberPrmtopFile(prmtop_filename)
        inpcrd = app.AmberInpcrdFile(inpcrd_filename)

        system = prmtop.createSystem(nonbondedMethod=app.PME, nonbondedCutoff=1.0*u.nanometers, constraints=app.HBonds)
예제 #48
0
def test_enter_temp_directory():
    with utils.enter_temp_directory():
        pass
예제 #49
0
def test_run_test_molecule():
    molecule_name = "sustiva"
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        utils.test_molecule(molecule_name, input_filename)
예제 #50
0
def test_run_test_molecule():
    molecule_name = "sustiva"
    input_filename = utils.get_data_filename("chemicals/sustiva/sustiva.mol2")
    with utils.enter_temp_directory():  # Prevents creating tons of GAFF files everywhere.
        utils.test_molecule(molecule_name, input_filename)
예제 #51
0
def test_link_in_utils():
    m0 = openmoltools.openeye.iupac_to_oemol("benzene")
    m1 = openmoltools.openeye.get_charges(m0)
    with utils.enter_temp_directory():
        # This function was moved from utils to openeye, so check that the old link still works.
        utils.molecule_to_mol2(m1, "out.mol2")
예제 #52
0
def test_charge_fail1():
    with assert_raises(RuntimeError):
        with utils.enter_temp_directory():
            openmoltools.openeye.smiles_to_antechamber(smiles_fails_with_strictStereo, "test.mol2",  "test.frcmod", strictStereo=True)
예제 #53
0
def test_charge_success1():
    with utils.enter_temp_directory():
        openmoltools.openeye.smiles_to_antechamber(smiles_fails_with_strictStereo, "test.mol2",  "test.frcmod", strictStereo=False)
예제 #54
0
def test_link_in_utils():
    m0 = openmoltools.openeye.iupac_to_oemol("benzene")
    m1 = openmoltools.openeye.get_charges(m0)
    with utils.enter_temp_directory():
        # This function was moved from utils to openeye, so check that the old link still works.
        utils.molecule_to_mol2(m1, "out.mol2")
예제 #55
0
def test_amber_water_mixture():
    water_filename = utils.get_data_filename("chemicals/water/water.mol2")
    etoh_filename = utils.get_data_filename("chemicals/etoh/etoh.mol2")
    sustiva_filename = utils.get_data_filename(
        "chemicals/sustiva/sustiva.mol2")

    with utils.enter_temp_directory(
    ):  # Prevents creating tons of GAFF files everywhere.
        shutil.copy(water_filename, 'c1.mol2')
        shutil.copy(etoh_filename, 'c2.mol2')
        shutil.copy(sustiva_filename, 'c3.mol2')
        water_filename = 'c1.mol2'
        etoh_filename = 'c2.mol2'
        sustiva_filename = 'c3.mol2'
        #Randomize residue names to avoid clashes
        utils.randomize_mol2_residue_names(
            [water_filename, etoh_filename, sustiva_filename])

        trj0, trj1, trj2 = md.load(water_filename), md.load(
            etoh_filename), md.load(sustiva_filename)

        trj_list = [trj0, trj1, trj2]

        box_filename = "./box.pdb"
        box_trj = packmol.pack_box(trj_list, [300, 25, 3])
        box_trj.save(box_filename)

        gaff_mol2_filename0, frcmod_filename0 = amber.run_antechamber(
            "water", water_filename, charge_method=None)
        gaff_mol2_filename1, frcmod_filename1 = amber.run_antechamber(
            "etoh", etoh_filename, charge_method=None)
        gaff_mol2_filename2, frcmod_filename2 = amber.run_antechamber(
            "sustiva", sustiva_filename, charge_method=None)

        mol2_filenames = [
            gaff_mol2_filename0, gaff_mol2_filename1, gaff_mol2_filename2
        ]
        frcmod_filenames = [
            frcmod_filename0, frcmod_filename1, frcmod_filename2
        ]

        prmtop_filename = "./out.prmtop"
        inpcrd_filename = "./out.inpcrd"

        shutil.copy(box_filename, 'renamed.pdb')
        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames,
                                               frcmod_filenames, 'renamed.pdb',
                                               prmtop_filename,
                                               inpcrd_filename)
        print(tleap_cmd)

        #Also do here for case of GAFF water
        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames,
                                               frcmod_filenames,
                                               box_filename,
                                               prmtop_filename,
                                               inpcrd_filename,
                                               water_model=None)
        print(tleap_cmd)

        #Also do here for case of SPC
        tleap_cmd = amber.build_mixture_prmtop(mol2_filenames,
                                               frcmod_filenames,
                                               'renamed.pdb',
                                               prmtop_filename,
                                               inpcrd_filename,
                                               water_model='SPC')
        print(tleap_cmd)