def test_hydrogen_bonds(self): # Test `hydrogen_bonds` function sel = Selection('noh') result = [ HydrogenBond(Atom(18), Atom(19), Atom(9)), HydrogenBond(Atom(9), Atom(11), Atom(6)), HydrogenBond(Atom(6), Atom(7), Atom(15)) ] self.assertEqual(list(hydrogen_bonds(sel)), result) self.assertEqual(list(hydrogen_bonds(sel, sel)), result) result = [ HydrogenBond(Atom(18), Atom(19), Atom(9)), HydrogenBond(Atom(9), Atom(11), Atom(6)), HydrogenBond(Atom(6), Atom(7), Atom(9)), HydrogenBond(Atom(6), Atom(7), Atom(15)) ] self.assertEqual(list(hydrogen_bonds(sel, angle=75)), result) self.assertEqual(list(hydrogen_bonds(sel, angle=180)), []) self.assertEqual(list(hydrogen_bonds(sel, distance=2)), []) # If the selections do not share same atoms, check the hydrogen bonds are returned only in correct direction sel1 = Selection('index 6') sel2 = Selection('index 9') self.assertEqual(list(hydrogen_bonds(sel1, sel2, angle=75)), [HydrogenBond(Atom(6), Atom(7), Atom(9))])
def test_properties(self): # Test basic properties VMD.molecule.load('psf', data('water.psf'), 'pdb', data('water.pdb')) sel = Selection('resid 1 to 3') # Test getters self.assertEqual(sel.selection, 'resid 1 to 3') # Test setters with self.assertRaises(AttributeError): sel.selection = 'none'
def test_selection_updates(self): # Test selection updates if frame is changed molid = VMD.molecule.load('psf', data('water.psf'), 'pdb', data('water.pdb')) VMD.molecule.read(molid, 'dcd', data('water.1.dcd'), waitfor=-1) mol = Molecule(molid) # Create selection linked to the molecule frame sel = Selection('x < -1.4') self.assertEqual(list(sel), [Atom(9), Atom(18), Atom(19), Atom(20)]) # Change the molecule frame, the selection should follow mol.frame = 0 self.assertEqual(list(sel), [ Atom(0), Atom(1), Atom(9), Atom(10), Atom(18), Atom(19), Atom(20) ]) mol.frame = 4 self.assertEqual( list(sel), [Atom(0), Atom(1), Atom(9), Atom(18), Atom(19), Atom(20)]) # Define the selection's frame result = [ Atom(0, frame=9), Atom(1, frame=9), Atom(9, frame=9), Atom(18, frame=9), Atom(19, frame=9), Atom(20, frame=9) ] sel.frame = 9 self.assertEqual(list(sel), result) # Change the molecule frame, the selection keeps its frame mol.frame = 11 self.assertEqual(list(sel), result) # Set the selection's frame back to the molecule's frame sel.frame = NOW self.assertEqual(list(sel), [Atom(9), Atom(18), Atom(19), Atom(20)])
def test_rmsd_collector(self): # Test RMSD collector ref = Molecule.create() ref.load(data('water.psf')) ref.load(data('water.pdb')) dset = DataSet() dset.add_collector(RMSDCollector('all', Selection('all', ref))) dset.add_collector( RMSDCollector('all and name OH2', Selection('all and name OH2', ref))) dset.add_collector( RMSDCollector('all and noh', Selection('all and noh', ref), name='noh')) analyzer = Analyzer(self.mol, [data('water.1.dcd')]) analyzer.add_dataset(dset) analyzer.analyze() # Write data to check result buf = StringIO() dset.write(buf) # Check the result self.assertEqual(buf.getvalue(), open(data('rmsd.dat')).read())
def test_contacts(self): # Test `contacts` method VMD.molecule.load('psf', data('water.psf'), 'pdb', data('water.pdb')) sel1 = Selection('resid 1 to 3 and noh') sel2 = Selection('hydrogen') self.assertEqual(list(sel1.contacts(sel2, 1.0)), []) self.assertEqual(list(sel1.contacts(sel2, 2.0)), [(Atom(6), Atom(11))]) self.assertEqual(list(sel2.contacts(sel1, 2.0)), [(Atom(11), Atom(6))])
def test_center(self): # Test `center` function. sel = Selection('all') # Center of selection self.assertAlmostEqualSeqs(list(center(sel)), [-0.0001906, 0.0004762, -0.0001429]) res = Residue(0) # Center of residue self.assertAlmostEqualSeqs(list(center(res)), [-1.3403333, 2.1406667, 0.967]) atom = Atom(0) # Center of atom - atom coordinates self.assertAlmostEqualSeqs(list(center(atom)), [-1.493, 1.9, 1.28]) # Center of atom iterables # The manuall computation seems to differ a bit from the `atomsel.center` self.assertAlmostEqualSeqs(list(center(iter(sel))), [-0.0001905, 0.0004762, -0.0001429]) self.assertAlmostEqualSeqs(list(center((Atom(i) for i in xrange(10)))), [-0.146, 0.3756, 0.3972])
def _get_selection(self): return Selection( _molrep.get_selection(self._molecule.molid, self.repindex), self._molecule)
import VMD from pyvmd import measure from pyvmd.atoms import Selection from pyvmd.molecules import Molecule, FORMAT_PDB, FORMAT_PSF TEMPLATE_PDB = '../structures/3j5p.pdb' TMP_DIR = tempfile.mkdtemp(prefix='vmd_') TOPOLOGY = '/usr/lib/vmd/plugins/noarch/tcl/readcharmmtop1.1/top_all27_prot_lipid_na.inp' # Load template template = Molecule.create() template.load(TEMPLATE_PDB) # Center the template center = measure.center(Selection('all', template)) Selection('all', template).atomsel.moveby((-center[0], -center[1], -center[2])) # Rotate the template, so model takes less space VMD.evaltcl('[atomselect %d all] move [transaxis z -35]' % template.molid) # Save individual chains for chain in 'ABCD': print "Saving monomer %s" % chain Selection('chain {} and resid 393 to 502'.format(chain), template).atomsel.write(FORMAT_PDB, '{}/{}1.pdb'.format(TMP_DIR, chain)) Selection('chain {} and resid 508 to 719'.format(chain), template).atomsel.write(FORMAT_PDB, '{}/{}2.pdb'.format(TMP_DIR, chain)) # Load psfgen and topology VMD.evaltcl("package require psfgen") VMD.evaltcl("topology %s" % TOPOLOGY) # Aliasing VMD.evaltcl("pdbalias residue HIS HSE")
from pyvmd.atoms import Selection from pyvmd.molecules import Molecule, FORMAT_PDB PSF = 'initial.psf' PDB = '00_minimize/00_minimize.coor' # Lipid tail simulation constraint LIPID_TAILS_PDB = 'tails_only.pdb' # Protein fixed simulation constraint PROTEIN_PDB = 'protein.pdb' # Protein CA constraint BACKBONE_CA_PDB = 'backbone_ca.pdb' model = Molecule.create() model.load(PSF) model.load(PDB, FORMAT_PDB) model_sel = Selection('all', model) model_sel.atomsel.set('beta', 0) # Lipid constraints # Fix all and release only the lipid tails model_sel.atomsel.set('occupancy', 1) Selection('lipid and not name N "C1[1-5]" "H[1-5]\d" P1 "O."', model).atomsel.set('occupancy', 0) model_sel.atomsel.write(FORMAT_PDB, LIPID_TAILS_PDB) # Protein constraints model_sel.atomsel.set('occupancy', 0) Selection('protein and noh', model).atomsel.set('occupancy', 1) model_sel.atomsel.write(FORMAT_PDB, PROTEIN_PDB) # Protein CA constraints model_sel.atomsel.set('occupancy', 0)