def __init__(self,dcd=None,psf=None,first=0,last=-1,stride=1,waitfor=-1,pdb=None): self.molID=0 if psf is not None: self.psf = psf self.molID=molecule.load('psf',psf) if (pdb is None) and (dcd is not None): try: self.dcd = dcd self.molID=molecule.new('new') self.molID=molecule.load('psf',self.psf) # load trajectory molecule.read(self.molID,'dcd',self.dcd,stride=stride,first=first,last=last,waitfor=waitfor) print ("DCD file detected id ",self.molID) except IOError: print ("Could not read dcd file or psf:", dcd) raise Exception() else: try: self.molID=molecule.new('pdb') self.pdb=pdb molecule.read(molid=self.molID,filetype ='pdb',filename=self.pdb,first=0,last=0) print ("pdb file detected id ",self.molID) except IOError: print ("Could not read dcd file or psf:",pdb) raise Exception()
def test_create(): m = molecule.new(name="test", natoms=3000) assert molecule.name(m) == "test" assert molecule.numatoms(m) == 3000 with pytest.raises(ValueError): m = molecule.new("test2", -2000) molecule.delete(m)
def test_materials(): mid = molecule.new(name="Test") graphics.materials(molid=mid, on=True) graphics.material(molid=mid, name="AOShiny") rc = graphics.sphere(molid=mid, center=(1,1,1), radius=5.1, resolution=8) assert graphics.info(mid, rc) == "sphere {1.000000 1.000000 1.000000} " +\ "radius 5.100000 resolution 8" with pytest.raises(ValueError): graphics.sphere(molid=mid, center=(1,1)) rc = graphics.text(mid, (0,0,0), "hello world", size=4.0, width=2.0) with pytest.raises(ValueError): graphics.text(mid, 0, "oops") assert graphics.info(mid, rc) == "text {0.000000 0.000000 0.000000} " + \ "{hello world} size 4.000000 thickness 2.000000" with pytest.raises(ValueError): graphics.info(mid+1, 3) with pytest.raises(IndexError): graphics.info(mid, 3000) graphics.delete(mid, rc) with pytest.raises(IndexError): graphics.info(mid, rc) molecule.delete(mid)
def __setstate__(self, state): name, files, types, reps = state self.id = molecule.new(name, 0) for file, type in zip(files, types): self.load(file, type) self.clearReps() for rep in reps: self.addRep(rep)
def pdb(self,pdb,psf=None): #sobrecarga para leer pdbs y no dcd try: self.molID=molecule.new('pdb') self.pdb=pdb if psf is not None: self.molID=molecule.load('psf',psf) self.psf=psf # add psf molecule.read(molid=self.molID,filetype ='pdb',filename=self.pdb,first=0,last=0) print (self.molID) except IOError: print ("Could not read dcd file or psf:",pdb) raise Exception()
def dcd(self,dcd,psf,first=0,last=-1,stride=1,waitfor=-1): self.psf = psf self.dcd = dcd self.molID=0 try: self.molID=molecule.new('new') self.molID=molecule.load('psf',self.psf) # load trajectory molecule.read(self.molID,'dcd',self.dcd,stride=stride,first=first,last=last,waitfor=waitfor) print (self.molID) except IOError: print ("Could not read dcd file or psf:", dcd) raise Exception()
def test_colors(): mid = molecule.new(name="colortest") graphics.color(mid, 1) graphics.color(mid, "blue2") with pytest.raises(ValueError): graphics.color(mid, -1) with pytest.raises(ValueError): graphics.color(mid, "not a color") with pytest.raises(TypeError): graphics.color(mid, 32.0) molecule.delete(mid)
def __init__(self, name=None, id=None, atoms=0): """ Creating a new Molecule instance with no arguments will create a new empty molecule in VMD. Passing a valid molecule id will make the Molecule instance mirror the state of the corresponding molecule in VMD. If id is None, and a name is given, the new molecule will have that name. """ if id is None: if name is None: name = "molecule" self.id = molecule.new(name, atoms) else: self.id = id self.atoms = molecule.numatoms(self.id) if not molecule.exists(self.id): raise ValueError("Molecule with id %d does not exist." % self.id)
def test_mol_descstrs(file_3frames): m1 = molecule.load("pdb", file_3frames) m2 = molecule.new(name="empty") # Filenames assert "ala_nma_3frames.pdb" in molecule.get_filenames(molid=m1)[0] assert molecule.get_filenames(m2) == [] with pytest.raises(ValueError): molecule.get_filenames(m2 + 1) # File types assert molecule.get_filetypes(molid=m1) == ["pdb"] assert molecule.get_filetypes(m2) == [] with pytest.raises(ValueError): molecule.get_filetypes(m2 + 1) # Databases assert molecule.get_databases(molid=m1) == ["PDB"] assert molecule.get_databases(m2) == [] with pytest.raises(ValueError): molecule.get_databases(m2 + 1) # Accessions assert molecule.get_accessions(molid=m1) == ["TEST"] assert molecule.get_accessions(m2) == [] with pytest.raises(ValueError): molecule.get_accessions(m2 + 1) # Remarks assert molecule.get_remarks(molid=m1) == ["REMARK 1 remark 1\nREMARK 2" \ " also remark 2\n"] assert molecule.get_remarks(m2) == [] with pytest.raises(ValueError): molecule.get_remarks(m2 + 1) molecule.delete(m1) molecule.delete(m2)
def test_mol_descstrs(file_3frames): m1 = molecule.load("pdb", file_3frames) m2 = molecule.new(name="empty") # Filenames assert "ala_nma_3frames.pdb" in molecule.get_filenames(molid=m1)[0] assert molecule.get_filenames(m2) == [] with pytest.raises(ValueError): molecule.get_filenames(m2+1) # File types assert molecule.get_filetypes(molid=m1) == ["pdb"] assert molecule.get_filetypes(m2) == [] with pytest.raises(ValueError): molecule.get_filetypes(m2+1) # Databases assert molecule.get_databases(molid=m1) == ["PDB"] assert molecule.get_databases(m2) == [] with pytest.raises(ValueError): molecule.get_databases(m2+1) # Accessions assert molecule.get_accessions(molid=m1) == ["TEST"] assert molecule.get_accessions(m2) == [] with pytest.raises(ValueError): molecule.get_accessions(m2+1) # Remarks assert molecule.get_remarks(molid=m1) == ["REMARK 1 remark 1\nREMARK 2" \ " also remark 2\n"] assert molecule.get_remarks(m2) == [] with pytest.raises(ValueError): molecule.get_remarks(m2+1) molecule.delete(m1) molecule.delete(m2)
def __init__(self, pdb_file, load_data=None, style=None, name='my_molecule', flush_pdb_frame=False, align=True, center=True): self.molid = mol.new(name) mol.rename(self.molid, name) self.name = name mol.read(self.molid, 'pdb', pdb_file, beg=0, end=0, skip=1, waitfor=-1) self.all_atoms = atomsel("all") if flush_pdb_frame: mol.delframe(self.molid) # flush trivial frame if load_data: self.load_data(load_data, align=align) if style: # delete the default representation molrep.delrep(self.molid, 0) for rep in style: molrep.addrep(self.molid, **rep)