def read_amber_conversion(self): qlib = QLib("amber") qlib.read_amber_lib("data/ff-amber14/amber12_mod.lib") qlib.read_amber_lib("data/ff-amber14/arn.lib") qlib.read_prepin_impropers("data/ff-amber14/prep/amino12.in") qlib.read_prepin_impropers("data/ff-amber14/arn.prepi") # remove head from ACE and tail from NME cons = qlib.residue_dict["ACE"].connections cons = [con for con in cons if "head" not in con] qlib.residue_dict["ACE"].connections = cons cons = qlib.residue_dict["NME"].connections cons = [con for con in cons if "tail" not in con] qlib.residue_dict["NME"].connections = cons assert qlib.get_string() in open("data/qamber14.lib").read()
# write the files # libfn = args.output_basename + ".lib" prmfn = args.output_basename + ".prm" prmchkfn = args.output_basename + ".prm.chk" print "Writing the library file: {}".format(libfn) backup = backup_file(libfn) if backup: print "# Backed up '{}' to '{}'".format(libfn, backup) outstring = """# Generated with {}, version {} # Date: {} # {} """.format(os.path.basename(__file__), __version__, time.ctime(), qlib.get_string()) open(libfn, "w").write(outstring) print "Writing the parameter file: {}".format(prmfn) backup = backup_file(prmfn) if backup: print "# Backed up '{}' to '{}'".format(prmfn, backup) outstring = """# Generated with {}, version {} # Date: {} # {} """.format(os.path.basename(__file__), __version__, time.ctime(), qprm.get_string()) open(prmfn, "w").write(outstring) print "Writing the parameter check file: {}".format(prmchkfn)
def test_ff14sb_conversion(): # Amber14FF to Qamber14 # # Convert Amber14 lib (+prepin for impropers) and parm+frcmod to Q lib/prm # Load the structure 'all_amino_acids.pdb' and build the topology # Check the total bonding energy contributions and number of bonding terms # and compare the library and parameter set with official qamber14. # qal = QLib("amber") qap = QPrm("amber", ignore_errors=True) # duplicates qal.read_amber_lib("data/ff-amber14/amber12_mod.lib") qal.read_amber_lib("data/ff-amber14/arn.lib") qal.read_prepin_impropers("data/ff-amber14/prep/amino12.in") qal.read_prepin_impropers("data/ff-amber14/arn.prepi") qap.read_amber_parm("data/ff-amber14/parm/parm10.dat") qap.read_amber_frcmod("data/ff-amber14/parm/frcmod.ff14SB") # add options to parameters for line in """\ name Q-Amber14SB type AMBER vdw_rule arithmetic !vdW combination rule (geometric or arithmetic) scale_14 0.8333 ! electrostatic 1-4 scaling factor switch_atoms off improper_potential periodic improper_definition explicit\ """.splitlines(): lf = line.split() qap.options[lf[0]] = " ".join(lf[1:]) # remove head from ACE and tail from NME cons = qal.residue_dict["ACE"].connections cons = [con for con in cons if "head" not in con] qal.residue_dict["ACE"].connections = cons cons = qal.residue_dict["NME"].connections cons = [con for con in cons if "tail" not in con] qal.residue_dict["NME"].connections = cons qas1 = QStruct("data/all_amino_acids.pdb", "pdb", ignore_errors=True) qat = QTopology(qal, qap, qas1) q_tors = sum([len(list(tor.prm.get_prms())) for tor in qat.torsions]) assert len(qat.bonds) == 464 assert len(qat.angles) == 829 assert len(qat.torsions) == 1221 assert q_tors == 1950 assert len(qat.impropers) == 102 be = sum([bond.calc()[0] for bond in qat.bonds]) ae = sum([ang.calc()[0] for ang in qat.angles]) te = sum([tor.calc()[0] for tor in qat.torsions]) ie = sum([imp.calc()[0] for imp in qat.impropers]) assert is_close(be, 181.2572830) assert is_close(ae, 212.8539304) assert is_close(te, 417.2919960) assert is_close(ie, 22.8171235) # compare with official lib qa14_lib = open("data/qamber14.lib", "r").read() qa14_prm = open("data/qamber14.prm", "r").read() assert qal.get_string() in qa14_lib assert qap.get_string() in qa14_prm
def test_convert_oplsaa(self): qlib = QLib("oplsaa") qstruct = QStruct("data/ace_ash_nma.pdb", "pdb") qlib.read_ffld("data/ace_ash_nma.ffld11", qstruct) ql_str = qlib.get_string() assert ql_str == open("data/ace_ash_nma.lib").read()
def test_read_write_lib(self): qlib = QLib("amber") qlib.read_lib("data/qamber14.lib") qlib.residue_dict.pop("HOH") # different order ql_str2 = qlib.get_string() assert ql_str2 in open("data/qamber14.lib", "r").read()
# write the files # libfn = args.output_basename + ".lib" prmfn = args.output_basename + ".prm" prmchkfn = args.output_basename + ".prm.chk" print("Writing the library file: {}".format(libfn)) backup = backup_file(libfn) if backup: print("# Backed up '{}' to '{}'".format(libfn, backup)) outstring = """# Generated with {}, version {} # Date: {} # {} """.format(os.path.basename(__file__), __version__, time.ctime(), qlib.get_string()) open(libfn, "w").write(outstring) # make a list of unique torsion prms # (generics for same atypes are returned from .prm_full as # separate _PrmTorsion objects) torsion_prms = [x.prm_full for x in qtop.torsions] torsion_prms_unique = {x.prm_id: x for x in torsion_prms}.values() improper_prms = [x.prm_full for x in qtop.impropers] improper_prms_unique = {x.prm_id: x for x in improper_prms}.values() print("Writing the parameter file: {}".format(prmfn)) backup = backup_file(prmfn) if backup: print("# Backed up '{}' to '{}'".format(prmfn, backup)) outstring = """# Generated with {}, version {}
switch_atoms off improper_potential periodic improper_definition explicit""".splitlines(): lf = line.split() qap.options[lf[0]] = " ".join(lf[1:]) # remove head from ACE and tail from NME cons = qal.residue_dict["ACE"].connections cons = [con for con in cons if "head" not in con] qal.residue_dict["ACE"].connections = cons cons = qal.residue_dict["NME"].connections cons = [con for con in cons if "tail" not in con] qal.residue_dict["NME"].connections = cons open("qamber14_gen.lib", "w").write(qal.get_string()) open("qamber14_gen.prm", "w").write(qap.get_string()) print "# Topology with converted parameters (and mol2):" qas1 = QStruct("../all_amino_acids.mol2", "mol2") qat = QTopology(qal, qap, qas1) q_tors = sum([len(list(tor.prm.get_prms())) for tor in qat.torsions]) print "Bonds: ", len(qat.bonds) print "Angles: ", len(qat.angles) print "Torsions: ", len(qat.torsions) print "Q Torsions (diff parms): ", q_tors print "Impropers: ", len(qat.impropers) print "Bond energy: ", sum([bond.calc()[0] for bond in qat.bonds]) print "Angle energy: ", sum([ang.calc()[0] for ang in qat.angles]) print "Torsion energy: ", sum([tor.calc()[0] for tor in qat.torsions]) print "Improper energy: ", sum([imp.calc()[0] for imp in qat.impropers])