def test_add_trajectory(): view = nv.NGLWidget(default=False) def update_coords(view=view): view.frame = 1000 view.frame = 0 p_traj = pt.load(nv.datafiles.TRR, nv.datafiles.PDB) view.add_trajectory(p_traj) m_traj = md.load(nv.datafiles.XTC, top=nv.datafiles.PDB) view.add_trajectory(m_traj) # trigger updating coordinates update_coords() assert len(view._coordinates_dict.keys()) == 2 if has_MDAnalysis: from MDAnalysis import Universe mda_traj = Universe(nv.datafiles.PDB, nv.datafiles.TRR) view.add_trajectory(mda_traj) update_coords() assert len(view._coordinates_dict.keys()) == 3 if has_HTMD: from htmd import Molecule htmd_traj = Molecule(nv.datafiles.PDB) htmd_traj.filter('protein') view.add_trajectory(htmd_traj) update_coords() if has_MDAnalysis: assert len(view._coordinates_dict.keys()) == 4 else: assert len(view._coordinates_dict.keys()) == 3
def test_add_trajectory(): view = nv.NGLWidget() def update_coords(view=view): view.frame = 1000 view.frame = 0 p_traj = pt.load(nv.datafiles.TRR, nv.datafiles.PDB) view.add_trajectory(p_traj) m_traj = md.load(nv.datafiles.XTC, top=nv.datafiles.PDB) view.add_trajectory(m_traj) # trigger updating coordinates update_coords() assert len(view.coordinates_dict.keys()) == 2 if has_MDAnalysis: from MDAnalysis import Universe mda_traj = Universe(nv.datafiles.PDB, nv.datafiles.TRR) view.add_trajectory(mda_traj) update_coords() assert len(view.coordinates_dict.keys()) == 3 if has_HTMD: from htmd import Molecule htmd_traj = Molecule(nv.datafiles.PDB) htmd_traj.filter('protein') view.add_trajectory(htmd_traj) update_coords() if has_MDAnalysis: assert len(view.coordinates_dict.keys()) == 4 else: assert len(view.coordinates_dict.keys()) == 3
def listDihedrals(filename): # This routine gets the names of the atoms in the soft dihedrals # It's so horrible, since we have to jump through hoops to # set up the input for gen_soft_list ll1 = [] ll2 = [] env = Parameterisation._preflight_test(None) mol = Molecule(filename); mol = Parameterisation._rename_mol(mol) mol.bonds = mol._guessBonds() # make a tempdir with tempfile.TemporaryDirectory() as td: # td=tempfile.mkdtemp() # print(td) pwd = os.getcwd() os.chdir(td) f = open("mol.prm", "w") f.close() mol.write("mol.pdb") mol.write("mol-opt.xyz") mol.write("mol.xpsf", type="psf") for charge in range(-1, 2): ret = subprocess.check_output( [env['BIN_MATCH'], "-charge", str(charge), "-forcefield", "top_all36_cgenff_new", "mol.pdb"], stderr=subprocess.STDOUT, shell=False, stdin=None) ret = subprocess.check_output([env['BIN_GEN_XPSF'], "mol.rtf", "mol.xpsf", "MOL"], stderr=subprocess.STDOUT, shell=False, stdin=None) ret = subprocess.check_output([env['BIN_GEN_SOFT_LIST']], stderr=subprocess.STDOUT, shell=False, stdin=None) f = open("soft-dih-list.txt", "r") ff = f.readlines() for l in ff: ss = [] tt = [] for m in l.split(): tt.append(int(m)) ss.append(mol.name[int(m) - 1].strip().upper()) ll1.append(tt) ll2.append(ss) f.close() os.chdir(pwd) return (ll1, ll2)
def test_show_htmd(): from htmd import Molecule fn = nv.datafiles.PDB traj = Molecule(fn) view = nv.show_htmd(traj) # trigger updating cooridnates view.frame = 100 index = 0 view.frame = index xyz_htmd = np.squeeze(traj.coords[:, :, index]) aa_eq(view._coordinates_dict[0], xyz_htmd)
def getParameters(self): import tempfile if not self.completed: raise ValueError("Parameterisation is not complete") # look for the right files in the output directory dir = os.path.join(self.directory, "999-results") rtf = os.path.join(dir, "mol.rtf") prm = os.path.join(dir, "mol.prm") xyz = os.path.join(dir, "mol.xyz") pdb = os.path.join(dir, "mol.pdb") rtf_tmp = tempfile.mkstemp(suffix=".rtf") prm_tmp = tempfile.mkstemp(suffix=".prm") pdb_tmp = tempfile.mkstemp(suffix=".pdb") xyz_tmp = tempfile.mkstemp(suffix=".xyz") os.close(rtf_tmp[0]) os.close(prm_tmp[0]) os.close(pdb_tmp[0]) os.close(xyz_tmp[0]) shutil.copyfile(rtf, rtf_tmp[1]) shutil.copyfile(prm, prm_tmp[1]) shutil.copyfile(xyz, xyz_tmp[1]) # The Output minimised structure is in XYZ format # Need to turn it into a PDB with correct atom naming mol = Molecule(xyz) Parameterisation._rename_mol(mol) # Canonicalise atom and reside naming mol.write(pdb_tmp[1]) return { "RTF": rtf_tmp[1], "PRM": prm_tmp[1], "PDB": pdb_tmp[1] }
def renameStructure(filename): m = Molecule(filename) m = Parameterisation._rename_mol(m) m.write(filename)