def test_amber_conversion(self): qp_str = open("data/qamber14.prm", "r").read() qp_str = re.sub("(\*|\!|#).*", "", qp_str) qp_str = re.sub("\s+$", "", qp_str, 0, re.MULTILINE) qp_str = re.sub("^\n", "", qp_str, 0, re.MULTILINE) qprm = QPrm("amber", ignore_errors=True) # duplicates qprm.read_amber_parm("data/ff-amber14/parm/parm10.dat") ow = qprm.read_amber_frcmod("data/ff-amber14/parm/frcmod.ff14SB") # add options section manually and compare with official lib for line in """\ name Q-Amber14SB type AMBER vdw_rule arithmetic scale_14 0.8333 switch_atoms off improper_potential periodic improper_definition explicit\ """.splitlines(): lf = line.split() qprm.options[lf[0]] = " ".join(lf[1:]) qp_str2 = qprm.get_string() qp_str2 = re.sub("\s+$", "", qp_str2, 0, re.MULTILINE) qp_str2 = re.sub("^\n", "", qp_str2, 0, re.MULTILINE) assert qp_str == qp_str2
def test_read_write_prm(self): qp_str = open("data/qamber14.prm", "r").read() qp_str = re.sub("(\*|\!|#).*", "", qp_str) qp_str = re.sub("\s+$", "", qp_str, 0, re.MULTILINE) qp_str = re.sub("^\n", "", qp_str, 0, re.MULTILINE) qprm = QPrm("amber") qprm.read_prm("data/qamber14.prm") qp_str2 = qprm.get_string() qp_str2 = re.sub("\s+$", "", qp_str2, 0, re.MULTILINE) qp_str2 = re.sub("^\n", "", qp_str2, 0, re.MULTILINE) assert qp_str == qp_str2
def test_read_write_prm2(self): qp_str = open("data/ace_ash_nma.prm", "r").read() qp_str = re.sub("(\*|\!|#).*", "", qp_str) qp_str = re.sub("\s+$", "", qp_str, 0, re.MULTILINE) qp_str = re.sub("^\n", "", qp_str, 0, re.MULTILINE) qprm = QPrm("oplsaa") qprm.read_prm("data/ace_ash_nma.prm") qp_str2 = qprm.get_string() qp_str2 = re.sub("(\*|\!|#).*", "", qp_str2) qp_str2 = re.sub("\s+$", "", qp_str2, 0, re.MULTILINE) qp_str2 = re.sub("^\n", "", qp_str2, 0, re.MULTILINE) assert qp_str == qp_str2
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) backup = backup_file(prmchkfn) if backup: print "# Backed up '{}' to '{}'".format(prmchkfn, backup) open(prmchkfn, "w").write("\n".join(pchk))
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
# 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 {} # Date: {} # {} """.format( os.path.basename(__file__), __version__, time.ctime(), qprm.get_string(atom_types=[x.prm for x in qtop.atoms], bonds=[x.prm for x in qtop.bonds], angles=[x.prm for x in qtop.angles], torsions=torsion_prms_unique, impropers=improper_prms_unique)) open(prmfn, "w").write(outstring) print("Writing the parameter check file: {}".format(prmchkfn)) backup = backup_file(prmchkfn) if backup: print("# Backed up '{}' to '{}'".format(prmchkfn, backup)) open(prmchkfn, "w").write("\n".join(pchk))
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])
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)) backup = backup_file(prmchkfn) if backup: print("# Backed up '{}' to '{}'".format(prmchkfn, backup)) open(prmchkfn, "w").write("\n".join(pchk))
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(atom_types=[x.prm for x in qtop.atoms], bonds=[x.prm for x in qtop.bonds], angles=[x.prm for x in qtop.angles], torsions=[x.prm_full for x in qtop.torsions], impropers=[x.prm_full for x in qtop.impropers])) open(prmfn, "w").write(outstring) print "Writing the parameter check file: {}".format(prmchkfn) backup = backup_file(prmchkfn) if backup: print "# Backed up '{}' to '{}'".format(prmchkfn, backup) open(prmchkfn, "w").write("\n".join(pchk))