Пример #1
0
 def phiPsi(self, conf = None):
     """
     :returns: a list of the (phi, psi) backbone angles for each residue
     :rtype: list of tuple of float
     """
     universe = self.universe()
     if universe is None:
         universe = Universe.InfiniteUniverse()
     angles = []
     for i in range(len(self)):
         r = self[i]
         if i == 0:
             phi = None
         else:
             phi = universe.dihedral(r.peptide.C, r.peptide.C_alpha,
                                     r.peptide.N,
                                     self[i-1].peptide.C, conf)
         if i == len(self)-1:
             psi = None
         else:
             psi = universe.dihedral(self[i+1].peptide.N,
                                     r.peptide.C, r.peptide.C_alpha,
                                     r.peptide.N, conf)
         angles.append((phi, psi))
     return angles
Пример #2
0
 def __init__(self,
              universe,
              force_field,
              subset1=None,
              subset2=None,
              threads=None,
              mpi_communicator=None):
     if not Universe.isUniverse(universe):
         raise TypeError("energy evaluator defined only for universes")
     self.universe = universe
     self.universe_version = self.universe._version
     self.ff = force_field
     self.configuration = self.universe.configuration()
     self.global_data = ForceFieldData()
     if subset1 is not None and subset2 is None:
         subset2 = subset1
     terms = self.ff.evaluatorTerms(self.universe, subset1, subset2,
                                    self.global_data)
     if not isinstance(terms, type([])):
         raise ValueError("evaluator term list not a list")
     from MMTK_forcefield import Evaluator
     if threads is None:
         import MMTK.ForceFields
         threads = MMTK.ForceFields.default_energy_threads
     self.evaluator = Evaluator(Numeric.array(terms), threads,
                                mpi_communicator)
Пример #3
0
 def phiPsi(self, conf = None):
     """
     :returns: the values of the backbone dihedral angles phi and psi.
     :rtype: tuple (float, float)
     """
     universe = self.universe()
     if universe is None:
         universe = Universe.InfiniteUniverse()
     C = None
     for a in self.peptide.N.bondedTo():
         if a.parent.parent != self:
             C = a
             break
     if C is None:
         phi = None
     else:
         phi = universe.dihedral(self.peptide.C, self.peptide.C_alpha,
                                 self.peptide.N, C, conf)
     N = None
     for a in self.peptide.C.bondedTo():
         if a.parent.parent != self:
             N = a
             break
     if N is None:
         psi = None
     else:
         psi = universe.dihedral(N, self.peptide.C, self.peptide.C_alpha,
                                 self.peptide.N, conf)
     return phi, psi
Пример #4
0
 def createUnitCellUniverse(self):
     """
     Constructs an empty universe (OrthrhombicPeriodicUniverse or
     ParallelepipedicPeriodicUniverse) representing the
     unit cell of the crystal. If the PDB file does not define
     a unit cell at all, an InfiniteUniverse is returned.
     
     :returns: a universe
     :rtype: :class:~MMTK.Universe.Universe
     """
     if self.from_fractional is None:
         return Universe.InfiniteUniverse()
     e1 = self.from_fractional(Vector(1., 0., 0.))
     e2 = self.from_fractional(Vector(0., 1., 0.))
     e3 = self.from_fractional(Vector(0., 0., 1.))
     if abs(e1.normal()*Vector(1., 0., 0.)-1.) < 1.e-15 \
            and abs(e2.normal()*Vector(0., 1., 0.)-1.) < 1.e-15 \
            and abs(e3.normal()*Vector(0., 0., 1.)-1.) < 1.e-15:
         return \
            Universe.OrthorhombicPeriodicUniverse((e1.length(),
                                                   e2.length(),
                                                   e3.length()))
     return Universe.ParallelepipedicPeriodicUniverse((e1, e2, e3))
Пример #5
0
def viewConfigurationVMD(object, configuration=None, format='pdb', label=None):
    from MMTK import Universe
    format = format.lower()
    if format != 'pdb':
        return genericViewConfiguration(object, configuration, format)
    tempfile.tempdir = tempdir
    filename = tempfile.mktemp()
    filename_tcl = filename.replace('\\', '\\\\')
    script = tempfile.mktemp()
    script_tcl = script.replace('\\', '\\\\')
    tempfile.tempdir = None
    object.writeToFile(filename, configuration, format)
    file = open(script, 'w')
    file.write('mol load pdb ' + filename_tcl + '\n')
    if isCalpha(object):
        file.write('mol modstyle 0 all trace\n')
    file.write('color Name 1 white\n')
    file.write('color Name 2 white\n')
    file.write('color Name 3 white\n')
    if Universe.isUniverse(object):
        # add a box around periodic universes
        basis = object.basisVectors()
        if basis is not None:
            v1, v2, v3 = basis
            p = -0.5 * (v1 + v2 + v3)
            for p1, p2 in [(p, p + v1), (p, p + v2), (p + v1, p + v1 + v2),
                           (p + v2, p + v1 + v2), (p, p + v3),
                           (p + v1, p + v1 + v3), (p + v2, p + v2 + v3),
                           (p + v1 + v2, p + v1 + v2 + v3),
                           (p + v3, p + v1 + v3), (p + v3, p + v2 + v3),
                           (p + v1 + v3, p + v1 + v2 + v3),
                           (p + v2 + v3, p + v1 + v2 + v3)]:
                file.write('graphics 0 line {%f %f %f} {%f %f %f}\n' %
                           (tuple(p1 / Units.Ang) + tuple(p2 / Units.Ang)))
    file.write('file delete ' + filename_tcl + '\n')
    if sys.platform != 'win32':
        # Under Windows, it seems to be impossible to delete
        # the script file while it is still in use. For the moment
        # we just don't delete it at all.
        file.write('file delete ' + script_tcl + '\n')
    file.close()
    subprocess.Popen([viewer['pdb'][1], '-nt', '-e', script])
Пример #6
0
    def __init__(self, universe, force_field, subset1=None, subset2=None,
                 threads=None, mpi_communicator=None):
	if not Universe.isUniverse(universe):
	    raise TypeError, "energy evaluator defined only for universes"
	self.universe = universe
	self.universe_version = self.universe._version
	self.ff = force_field
	self.configuration = self.universe.configuration()
	self.global_data = ForceFieldData()
	if subset1 is not None and subset2 is None:
	    subset2 = subset1
	terms = self.ff.evaluatorTerms(self.universe,
                                            subset1, subset2,
                                            self.global_data)
        from MMTK_forcefield import Evaluator
        if threads is None:
            import MMTK.ForceFields
            threads = MMTK.ForceFields.default_energy_threads;
        self.evaluator = Evaluator(Numeric.array(terms), threads,
                                   mpi_communicator)
Пример #7
0
def viewConfigurationVMD(object, configuration = None, format = 'pdb',
                      label = None):
    from MMTK import Universe
    format = format.lower()
    if format != 'pdb':
        return genericViewConfiguration(object, configuration, format)
    tempfile.tempdir = tempdir
    filename = tempfile.mktemp()
    filename_tcl = filename.replace('\\', '\\\\')
    script = tempfile.mktemp()
    script_tcl = script.replace('\\', '\\\\')
    tempfile.tempdir = None
    object.writeToFile(filename, configuration, format)
    file = open(script, 'w')
    file.write('mol load pdb ' + filename_tcl + '\n')
    if isCalpha(object):
        file.write('mol modstyle 0 all trace\n')
    file.write('color Name 1 white\n')
    file.write('color Name 2 white\n')
    file.write('color Name 3 white\n')
    if Universe.isUniverse(object):
        # add a box around periodic universes
        basis = object.basisVectors()
        if basis is not None:
            v1, v2, v3 = basis
            p = -0.5*(v1+v2+v3)
            for p1, p2 in [(p, p+v1), (p, p+v2), (p+v1, p+v1+v2),
                           (p+v2, p+v1+v2), (p, p+v3), (p+v1, p+v1+v3),
                           (p+v2, p+v2+v3), (p+v1+v2, p+v1+v2+v3),
                           (p+v3, p+v1+v3), (p+v3, p+v2+v3),
                           (p+v1+v3, p+v1+v2+v3), (p+v2+v3, p+v1+v2+v3)]:
                file.write('graphics 0 line {%f %f %f} {%f %f %f}\n' %
                           (tuple(p1/Units.Ang) + tuple(p2/Units.Ang)))
    file.write('file delete ' + filename_tcl + '\n')
    if sys.platform != 'win32':
            # Under Windows, it seems to be impossible to delete
            # the script file while it is still in use. For the moment
            # we just don't delete it at all.
        file.write('file delete ' + script_tcl + '\n')
    file.close()
    subprocess.Popen([viewer['pdb'][1], '-nt', '-e', script])
Пример #8
0
 def graphicsObjects(self, **options):
     """
     :keyword configuration: the configuration in which the objects
                             are drawn (default: the current configuration)
     :type configuration: :class:`~MMTK.ParticleProperties.Configuration`
     :keyword model: the graphical representation to be used (one of
                     "wireframe", "tube", "ball_and_stick", "vdw" and
                     "vdw_and_stick").  The vdw models use balls
                     with the radii taken from the atom objects.
                     Default is "wireframe".
     :type model: str
     :keyword ball_radius: the radius of the balls representing the atoms
                           in a ball_and_stick model, default: 0.03
                           This is also used in vdw and vdw_and_stick when
                           an atom does not supply a radius.
     :type ball_radius: float
     :keyword stick_radius: the radius of the sticks representing the bonds
                            in a ball_and_stick, vdw_and_stick or tube model.
                            Default: 0.02 for the tube model, 0.01 for the
                            ball_and_stick and vdw_and_stick models
     :type stick_radius: float
     :keyword graphics_module: the module in which the elementary graphics
                               objects are defined
                               (default: Scientific.Visualization.VRML)
     :type graphics_module: module
     :keyword color_values:  a color value for each atom which defines
                             the color via the color scale object specified
                             by the option color_scale. If no value is
                             given, the atoms' colors are taken from the
                             attribute 'color' of each atom object (default
                             values for each chemical element are provided
                             in the chemical database).
     :type  color_values: :class:`~MMTK.ParticleProperties.ParticleScalar`
     :keyword color_scale: an object that returns a color object (as defined
                           in the module Scientific.Visualization.Color)
                           when called with a number argument. Suitable
                           objects are defined by
                           Scientific.Visualization.Color.ColorScale and
                           Scientific.Visualization.Color.SymmetricColorScale.
                           The object is used only when the option
                           color_values is specified as well. The default
                           is a blue-to-red color scale that covers the
                           range of the values given in color_values.
     :type color_scale: callable
     :keyword color: a color name predefined in the module
                     Scientific.Visualization.Color. The corresponding
                     color is applied to all graphics objects that are
                     returned.
     :returns: a list of graphics objects that represent
               the object for which the method is called.
     :rtype: list
     """
     conf = options.get('configuration', None)
     model = options.get('model', 'wireframe')
     if model == 'tube':
         model = 'ball_and_stick'
         radius = options.get('stick_radius', 0.02)
         options['stick_radius'] = radius
         options['ball_radius'] = radius
     try:
         module = options['graphics_module']
     except KeyError:
         from Scientific.Visualization import VRML
         module = VRML
     color = options.get('color', None)
     if color is None:
         color_values = options.get('color_values', None)
         if color_values is not None:
             lower = N.minimum.reduce(color_values.array)
             upper = N.maximum.reduce(color_values.array)
             options['color_scale'] = module.ColorScale((lower, upper))
     try:
         distance_fn = self.universe().distanceVector
     except AttributeError:
         from MMTK import Universe
         distance_fn = Universe.InfiniteUniverse().distanceVector
     return self._graphics(conf, distance_fn, model, module, options)