Esempio n. 1
0
 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()
Esempio n. 2
0
 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()
Esempio n. 3
0
 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()
Esempio n. 4
0
def test_read(file_3frames):

    m = molecule.load("pdb", file_3frames)
    assert molecule.numframes(molid=m) == 3

    with pytest.warns(DeprecationWarning):
        molecule.read(m, "pdb", filename=file_3frames,
                      beg=1, end=1, skip=1, waitfor=-1)
    assert molecule.numframes(m) == 4

    molecule.read(molid=m, filetype="pdb", filename=file_3frames,
                  waitfor=1)
    molecule.cancel(m)
    assert molecule.numframes(m) < 6
    with pytest.raises(ValueError):
        molecule.cancel(molid=m+1)

    molecule.delete(m)
Esempio n. 5
0
    def load_data(self, load_data, align=True):
        """Method for loading trajectory data

        Parameters
        ----------
        load_data : dict
           dictionary of VMD read routine options. See
           VMDMolecule.__init__() docs.
        """

        if not isinstance(load_data, dict):
            raise ValueError("load_data must be a dictionary with "
                             "key-value pairs corresponding to VMD "
                             "read command options.")
        else:
            mol.read(self.molid, **load_data)
            if align:
                self.self_align()
            print("{} frames loaded.".format(mol.numframes(self.molid)))
            evaltcl("display resetview")
Esempio n. 6
0
 def load(self, filename, filetype=None, first=0, last=-1, step=1, waitfor=-1, volsets=[0]):
   """
   Load molecule data from the given file.  The filetype will be guessed from
   the filename extension; this can be overridden by setting the filetype
   option.  first, last, and step control which coordinates frames to load,
   if any.
   """
   if filetype is None:
     filetype = self._guessFiletype(filename)
   if molecule.read(self.id, filetype, filename, first, last, step, waitfor, volsets) < 0:
     raise IOError("Unable to load file: %s" % filename)
   return self
Esempio n. 7
0
def test_read(file_3frames):

    m = molecule.load("pdb", file_3frames)
    assert molecule.numframes(molid=m) == 3

    with pytest.warns(DeprecationWarning):
        molecule.read(m,
                      "pdb",
                      filename=file_3frames,
                      beg=1,
                      end=1,
                      skip=1,
                      waitfor=-1)
    assert molecule.numframes(m) == 4

    molecule.read(molid=m, filetype="pdb", filename=file_3frames, waitfor=1)
    molecule.cancel(m)
    assert molecule.numframes(m) < 6
    with pytest.raises(ValueError):
        molecule.cancel(molid=m + 1)

    molecule.delete(m)
Esempio n. 8
0
    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)
Esempio n. 9
0
    def get_cell_size(self,
                      mem_buf, wat_buf,
                      molid=None,
                      filename=None,
                      zh_mem_full=_MEMBRANE_FULL_THICKNESS / 2.0,
                      zh_mem_hyd=_MEMBRANE_HYDROPHOBIC_THICKNESS / 2.0):
        """
        Gets the cell size of the final system given initial system and
        buffers. Detects whether or not a membrane is present. Sets the
        size of the system.

        Args:
          mem_buf (float) : Membrane (xy) buffer amount
          wat_buf (float) : Water (z) buffer amount
          molid (int) : VMD molecule ID to consider (can't use with filename)
          filename (str) : Filename of system to consider (can't use w molid)
          zh_mem_full (float) : Membrane thickness
          zh_mem_hyd (float) : Membrane hydrophobic region thickness

        Returns:
        return dx_sol, dy_sol, dx_tm, dy_tm, dz_full
          (float tuple): x solute dimension, y solute dimension,
            TM x solute dimension, TM y solute dimension, solute z dimension

        Raises:
          ValueError: if filename and molid are both specified
        """

        # Sanity check
        if filename is not None and molid is not None:
            raise ValueError("Specified molid and filename to get_cell_size")

        if filename is not None:
            top = molecule.get_top()
            molid = molecule.read(-1, 'mae', filename)
        elif molid is None:
            molid = molecule.get_top()

        # Some options different for water-only systems (no lipid)
        if self.water_only:
            solute_z = atomsel(self.solute_sel, molid=molid).get('z')
            dx_tm = 0.0
            dy_tm = 0.0
            sol_solute = atomsel(self.solute_sel, molid)
        else:
            solute_z = atomsel(self.solute_sel, molid=molid).get('z')
            tm_solute = atomsel('(%s) and z > %f and z < %f' % (self.solute_sel,
                                                                -zh_mem_hyd,
                                                                zh_mem_hyd), molid)
            if len(tm_solute):
                dx_tm = max(tm_solute.get('x')) - min(tm_solute.get('x'))
                dy_tm = max(tm_solute.get('y')) - min(tm_solute.get('y'))
            else:
                dx_tm = dy_tm = 0

            sol_solute = atomsel('(%s) and (z < %f or z > %f)' % (self.solute_sel,
                                                                  -zh_mem_hyd,
                                                                  zh_mem_hyd), molid)

        # Solvent invariant options
        dx_sol = max(sol_solute.get('x')) - min(sol_solute.get('x'))
        dy_sol = max(sol_solute.get('y')) - min(sol_solute.get('y'))

        if self.opts.get('user_x'):
            self.size[0] = self.opts['user_x']
        else:
            self.size[0] = max(dx_tm + 2.*mem_buf, dx_sol + 2.*wat_buf)
        if self.opts.get('user_y'):
            self.size[1] = self.opts['user_y']
        else:
            self.size[1] = max(dy_tm + 2.*mem_buf, dy_sol + 2.*wat_buf)

        # Z dimension. If there's a membrane, need to account for asymmetry
        # in the Z dimension where the protein could be uneven in the membrane
        # or even peripheral
        if self.opts.get('user_z'):
            self.size[2] = self.opts['user_z']
            buf = (self.opts['user_z'] - max(solute_z) + min(solute_z))/2
            self._zmax = max(solute_z) + buf
            self._zmin = min(solute_z) - buf
            if zh_mem_full > self._zmax or -zh_mem_full < self._zmin:
                raise ValueError("Specified user z of %f is too small to "
                                 "accomodate protein and membrane!"
                                 % self.opts['user_z'])
        else:
            if self.water_only:
                self._zmax = max(solute_z) + wat_buf
                self._zmin = min(solute_z) - wat_buf
            else:
                self._zmax = max(max(solute_z)+wat_buf, zh_mem_full)
                self._zmin = min(min(solute_z)-wat_buf, -zh_mem_full)
            self.size[2] = self._zmax - self._zmin

        # Cleanup temporary file, if read in
        if filename is not None:
            molecule.delete(molid)
            if top != -1:
                molecule.set_top(top)

        return dx_sol, dy_sol, dx_tm, dy_tm, max(solute_z)-min(solute_z)
Esempio n. 10
0
    def get_cell_size(self,
                      mem_buf,
                      wat_buf,
                      molid=None,
                      filename=None,
                      zh_mem_full=_MEMBRANE_FULL_THICKNESS / 2.0,
                      zh_mem_hyd=_MEMBRANE_HYDROPHOBIC_THICKNESS / 2.0):
        """
        Gets the cell size of the final system given initial system and
        buffers. Detects whether or not a membrane is present. Sets the
        size of the system.

        Args:
          mem_buf (float) : Membrane (xy) buffer amount
          wat_buf (float) : Water (z) buffer amount
          molid (int) : VMD molecule ID to consider (can't use with filename)
          filename (str) : Filename of system to consider (can't use w molid)
          zh_mem_full (float) : Membrane thickness
          zh_mem_hyd (float) : Membrane hydrophobic region thickness

        Returns:
        return dx_sol, dy_sol, dx_tm, dy_tm, dz_full
          (float tuple): x solute dimension, y solute dimension,
            TM x solute dimension, TM y solute dimension, solute z dimension

        Raises:
          ValueError: if filename and molid are both specified
        """

        # Sanity check
        if filename is not None and molid is not None:
            raise ValueError("Specified molid and filename to get_cell_size")

        if filename is not None:
            top = molecule.get_top()
            molid = molecule.read(-1, 'mae', filename)
        elif molid is None:
            molid = molecule.get_top()

        # Some options different for water-only systems (no lipid)
        if self.water_only:
            solute_z = atomsel(self.solute_sel, molid=molid).get('z')
            dx_tm = 0.0
            dy_tm = 0.0
            sol_solute = atomsel(self.solute_sel, molid)
        else:
            solute_z = atomsel(self.solute_sel, molid=molid).get('z')
            tm_solute = atomsel(
                '(%s) and z > %f and z < %f' %
                (self.solute_sel, -zh_mem_hyd, zh_mem_hyd), molid)
            if len(tm_solute):
                dx_tm = max(tm_solute.get('x')) - min(tm_solute.get('x'))
                dy_tm = max(tm_solute.get('y')) - min(tm_solute.get('y'))
            else:
                dx_tm = dy_tm = 0

            sol_solute = atomsel(
                '(%s) and (z < %f or z > %f)' %
                (self.solute_sel, -zh_mem_hyd, zh_mem_hyd), molid)

        # Solvent invariant options
        dx_sol = max(sol_solute.get('x')) - min(sol_solute.get('x'))
        dy_sol = max(sol_solute.get('y')) - min(sol_solute.get('y'))

        if self.opts.get('user_x'):
            self.size[0] = self.opts['user_x']
        else:
            self.size[0] = max(dx_tm + 2. * mem_buf, dx_sol + 2. * wat_buf)
        if self.opts.get('user_y'):
            self.size[1] = self.opts['user_y']
        else:
            self.size[1] = max(dy_tm + 2. * mem_buf, dy_sol + 2. * wat_buf)

        # Z dimension. If there's a membrane, need to account for asymmetry
        # in the Z dimension where the protein could be uneven in the membrane
        # or even peripheral
        if self.opts.get('user_z'):
            self.size[2] = self.opts['user_z']
            buf = (self.opts['user_z'] - max(solute_z) + min(solute_z)) / 2
            self._zmax = max(solute_z) + buf
            self._zmin = min(solute_z) - buf
            if zh_mem_full > self._zmax or -zh_mem_full < self._zmin:
                raise DabbleError("Specified user z of %f is too small to "
                                  "accomodate protein and membrane!" %
                                  self.opts['user_z'])
        else:
            if self.water_only:
                self._zmax = max(solute_z) + wat_buf
                self._zmin = min(solute_z) - wat_buf
            else:
                self._zmax = max(max(solute_z) + wat_buf, zh_mem_full)
                self._zmin = min(min(solute_z) - wat_buf, -zh_mem_full)
            self.size[2] = self._zmax - self._zmin

        # Cleanup temporary file, if read in
        if filename is not None:
            molecule.delete(molid)
            if top != -1:
                molecule.set_top(top)

        return dx_sol, dy_sol, dx_tm, dy_tm, max(solute_z) - min(solute_z)
Esempio n. 11
0
def test_volumetric(file_psf, file_dx):

    # Test read with a volumetric dataset
    m = molecule.load("psf", file_psf)
    molecule.read(m, "dx", file_dx, volsets=[0])

    # Num volumetric
    assert molecule.num_volumetric(m) == 1
    with pytest.raises(ValueError):
        molecule.num_volumetric(m + 1)

    # Test with an invalid dataset index, nothing should be read
    molecule.read(m, "dx", file_dx, volsets=[1])
    assert molecule.num_volumetric(m) == 1

    # Get volumetric
    v = molecule.get_volumetric(m, 0)
    assert len(v) == 4
    assert len(v[0]) == 646875
    assert v[1] == (75, 75, 115)
    assert v[2] == pytest.approx((-37.0, -37.0, -57.0))
    assert len(v[3]) == 9
    del v

    with pytest.raises(ValueError):
        molecule.get_volumetric(m + 1, 0)
    with pytest.raises(ValueError):
        molecule.get_volumetric(molid=m, dataindex=200)

    # Delete volumetric, deprecated invocation
    with pytest.warns(DeprecationWarning):
        molecule.remove_volumetric(molid=m, dataindex=0)
    assert molecule.num_volumetric(m) == 0

    # Add volumetric
    newvol = list(np.ones((3, 6, 10)).flatten())

    # separate size keywords are deprecated
    with pytest.warns(DeprecationWarning):
        molecule.add_volumetric(molid=m,
                                name="testvol",
                                xsize=3,
                                ysize=6,
                                zsize=10,
                                data=newvol)
    assert molecule.num_volumetric(m) == 1
    nv = molecule.get_volumetric(m, 0)

    assert nv[0] == newvol
    assert nv[1] == (3, 6, 10)
    assert nv[2] == (0, 0, 0)
    assert nv[3] == tuple(np.identity(3).flatten())

    # Test a reasonable invocation of add with most keywords
    molecule.add_volumetric(m,
                            "testvol",
                            size=(3, 6, 10),
                            data=newvol,
                            origin=(10, 20, -10),
                            xaxis=(0, 1, 0))
    assert molecule.num_volumetric(molid=m) == 2

    nv = molecule.get_volumetric(m, 1)
    assert nv[0] == newvol
    assert nv[1] == (3, 6, 10)
    assert nv[2] == (10, 20, -10)
    assert nv[3][:3] == (0, 1, 0)

    # Invalid size
    with pytest.raises(ValueError):
        molecule.add_volumetric(m, "wrongsize", size=(1, 0, 1), data=[3])

    # Not matching dimensions
    with pytest.raises(ValueError):
        molecule.add_volumetric(m, "wrondim", size=(10, 1, 3), data=newvol)

    # Data not a sequence
    with pytest.raises(TypeError):
        molecule.add_volumetric(m, "wrongtype", size=(2, 3, 2), data=True)

    # Non-float items in data
    with pytest.raises(TypeError):
        molecule.add_volumetric(m,
                                "wrongdata",
                                size=(1, 1, 2),
                                data=[3.0, True])

    # Delete correctly
    molecule.delete_volumetric(molid=m, dataindex=1)
    assert molecule.num_volumetric(m) == 1

    # Delete wrong things
    with pytest.raises(ValueError):
        molecule.delete_volumetric(m + 1, dataindex=0)

    with pytest.raises(ValueError):
        molecule.delete_volumetric(m, 1)

    molecule.delete(m)
Esempio n. 12
0
def test_volumetric(file_psf, file_dx):

    # Test read with a volumetric dataset
    m = molecule.load("psf", file_psf)
    molecule.read(m, "dx", file_dx, volsets=[0])

    # Num volumetric
    assert molecule.num_volumetric(m) == 1
    with pytest.raises(ValueError):
        molecule.num_volumetric(m+1)

    # Test with an invalid dataset index, nothing should be read
    molecule.read(m, "dx", file_dx, volsets=[1])
    assert molecule.num_volumetric(m) == 1

    # Get volumetric
    v = molecule.get_volumetric(m, 0)
    assert len(v) == 4
    assert len(v[0]) == 646875
    assert v[1] == (75, 75, 115)
    assert v[2] == pytest.approx((-37.0, -37.0, -57.0))
    assert len(v[3]) == 9
    del v

    with pytest.raises(ValueError):
        molecule.get_volumetric(m+1, 0)
    with pytest.raises(ValueError):
        molecule.get_volumetric(molid=m, dataindex=200)

    # Delete volumetric, deprecated invocation
    with pytest.warns(DeprecationWarning):
        molecule.remove_volumetric(molid=m, dataindex=0)
    assert molecule.num_volumetric(m) == 0

    # Add volumetric
    newvol = list(np.ones((3,6,10)).flatten())

    # separate size keywords are deprecated
    with pytest.warns(DeprecationWarning):
        molecule.add_volumetric(molid=m, name="testvol", xsize=3, ysize=6,
                                zsize=10, data=newvol)
    assert molecule.num_volumetric(m) == 1
    nv = molecule.get_volumetric(m, 0)

    assert nv[0] == newvol
    assert nv[1] == (3, 6, 10)
    assert nv[2] == (0, 0, 0)
    assert nv[3] == tuple(np.identity(3).flatten())

    # Test a reasonable invocation of add with most keywords
    molecule.add_volumetric(m, "testvol", size=(3,6,10), data=newvol,
                            origin=(10,20,-10), xaxis=(0, 1, 0))
    assert molecule.num_volumetric(molid=m) == 2

    nv = molecule.get_volumetric(m, 1)
    assert nv[0] == newvol
    assert nv[1] == (3, 6, 10)
    assert nv[2] == (10, 20, -10)
    assert nv[3][:3] == (0, 1, 0)

    # Invalid size
    with pytest.raises(ValueError):
        molecule.add_volumetric(m, "wrongsize", size=(1, 0, 1), data=[3])

    # Not matching dimensions
    with pytest.raises(ValueError):
        molecule.add_volumetric(m, "wrondim", size=(10, 1, 3), data=newvol)

    # Data not a sequence
    with pytest.raises(TypeError):
        molecule.add_volumetric(m, "wrongtype", size=(2,3,2), data=True)

    # Non-float items in data
    with pytest.raises(TypeError):
        molecule.add_volumetric(m, "wrongdata", size=(1,1,2), data=[3.0, True])

    # Delete correctly
    molecule.delete_volumetric(molid=m, dataindex=1)
    assert molecule.num_volumetric(m) == 1

    # Delete wrong things
    with pytest.raises(ValueError):
        molecule.delete_volumetric(m+1, dataindex=0)

    with pytest.raises(ValueError):
        molecule.delete_volumetric(m, 1)

    molecule.delete(m)