示例#1
0
    def convert_forces_to_native(self, force, inplace=True):
        """In-place conversion of force array *force* from base units to native units.

        By default, the input *force* is modified in place and also returned.

        .. versionadded:: 0.7.7
        """
        f = units.get_conversion_factor("force", MDAnalysis.core.flags["force_unit"], self.units["force"])
        if f == 1.0:
            return force
        if not inplace:
            return f * force
        force *= f
        return force
示例#2
0
    def convert_velocities_to_native(self, v, inplace=True):
        """In-place conversion of coordinate array *v* from base units to native units.

        By default, the input *v* is modified in place and also returned.

        .. versionadded:: 0.7.5
        """
        f = units.get_conversion_factor("speed", MDAnalysis.core.flags["speed_unit"], self.units["velocity"])
        if f == 1.0:
            return v
        if not inplace:
            return f * v
        v *= f
        return v
示例#3
0
    def convert_forces_from_native(self, force, inplace=True):
        """In-place conversion of forces array *force* from native units to base units.

        By default, the input *force* is modified in place and also returned.

        .. versionadded:: 0.7.7
        """
        f = units.get_conversion_factor('force', self.units['force'],
                                        MDAnalysis.core.flags['force_unit'])
        if f == 1.:
            return force
        if not inplace:
            return f * force
        force *= f
        return force
示例#4
0
    def convert_velocities_from_native(self, v, inplace=True):
        """In-place conversion of velocities array *v* from native units to base units.

        By default, the input *v* is modified in place and also returned.

        .. versionadded:: 0.7.5
        """
        f = units.get_conversion_factor('speed', self.units['velocity'],
                                        MDAnalysis.core.flags['speed_unit'])
        if f == 1.:
            return v
        if not inplace:
            return f * v
        v *= f
        return v
示例#5
0
    def convert_pos_to_native(self, x, inplace=True):
        """Conversion of coordinate array x from base units to native units.

        By default, the input *x* is modified in place and also returned.

        .. versionchanged:: 0.7.5
           Keyword *inplace* can be set to ``False`` so that a
           modified copy is returned *unless* no conversion takes
           place, in which case the reference to the unmodified *x* is
           returned.

        """
        f = units.get_conversion_factor("length", MDAnalysis.core.flags["length_unit"], self.units["length"])
        if f == 1.0:
            return x
        if not inplace:
            return f * x
        x *= f
        return x
示例#6
0
    def convert_pos_from_native(self, x, inplace=True):
        """In-place conversion of coordinate array x from native units to base units.

        By default, the input *x* is modified in place and also returned.

        .. versionchanged:: 0.7.5
           Keyword *inplace* can be set to ``False`` so that a
           modified copy is returned *unless* no conversion takes
           place, in which case the reference to the unmodified *x* is
           returned.

        """
        f = units.get_conversion_factor('length', self.units['length'],
                                        MDAnalysis.core.flags['length_unit'])
        if f == 1.:
            return x
        if not inplace:
            return f * x
        x *= f
        return x
示例#7
0
    def convert_time_to_native(self, t, inplace=True):
        """Convert time *t* from base units to native units.

        By default, the input *t* is modified in place and also
        returned. (Also note that scalar values *t* are passed by
        value in Python and hence an in-place modification has no
        effect on the caller.)

        .. versionchanged:: 0.7.5
           Keyword *inplace* can be set to ``False`` so that a
           modified copy is returned *unless* no conversion takes
           place, in which case the reference to the unmodified *x* is
           returned.

        """
        f = units.get_conversion_factor("time", MDAnalysis.core.flags["time_unit"], self.units["time"])
        if f == 1.0:
            return t
        if not inplace:
            return f * t
        t *= f
        return t
示例#8
0
    def convert_time_from_native(self, t, inplace=True):
        """Convert time *t* from native units to base units.

        By default, the input *t* is modified in place and also
        returned (although note that scalar values *t* are passed by
        value in Python and hence an in-place modification has no
        effect on the caller.)

        .. versionchanged:: 0.7.5
           Keyword *inplace* can be set to ``False`` so that a
           modified copy is returned *unless* no conversion takes
           place, in which case the reference to the unmodified *x* is
           returned.

        """
        f = units.get_conversion_factor('time', self.units['time'],
                                        MDAnalysis.core.flags['time_unit'])
        if f == 1.:
            return t
        if not inplace:
            return f * t
        t *= f
        return t
示例#9
0
    def write(self,filename,start=None,step=None,delta=None,load=True):
        """Write hopping trajectory as standard dcd file, together with a minimal psf.

        write('hop')

        Arguments:

        load = True     Immediately loads the trajectory so that further
                        calls to next() will use the computed
                        trajectory and don't use expensive mapping.

        Ignore the other options and leave them at the
        defaults. Currently, only the whole trajectory is written. For
        visualization one also needs the dummy psf of the group.

        Results:

        filename.trajectory and filename.psf

        Note that it is your responsibility to load the hopping
        trajectory and the appropriate psf together as there is very
        limited information stored in the dcd itself.
        """
        set_verbosity(self.verbosity)  # this is stupid

        psfname = self.filename(filename,'psf')
        dcdname = self.filename(filename,'dcd')

        # see MDAnalysis/src/dcd/dcd.c for explanations;
        # other trajectories do not have certain values so we just fake them...
        if start is None:
            try:
                start = self.traj.start_timestep # starting time step for DCD file
            except AttributeError:
                start = 1
        if step is None:
            try:
                step = self.traj.skip_timestep   # NSAVC (# ts between written DCD frames)
            except AttributeError:
                step = 1
        if delta is None:
            from MDAnalysis.core.units import get_conversion_factor
            delta_ps = self.traj.convert_time_from_native(self.traj.delta)  # length of ts in ps
            delta = get_conversion_factor('time', 'ps', 'AKMA') * delta_ps

        dcdwriter = MDAnalysis.coordinates.DCD.DCDWriter(dcdname,self.ts.numatoms,
                                             start,step,delta,
                                             remarks='Hopping trajectory: x=site y=orbit_site z=0')
        pm = ProgressMeter(self.numframes, interval=10,
                           format="Mapping frame %(step)5d/%(numsteps)6d  [%(percentage)5.1f%%]\r")
        for ts in self.map_dcd():
            dcdwriter.write_next_timestep(ts)
            pm.echo(ts.frame)
	    dcdwriter.close()
        logger.info("HoppingTrajectory.write(): wrote hoptraj %r.", dcdname)

        self.write_psf(psfname)
        logger.info("HoppingTrajectory.write(): wrote hoppsf %r.", psfname)

        if load is True:
            self.__init__(filename=filename,verbosity=self.verbosity)