Пример #1
0
 def post(self, iterative):
     # Needed to correct the conserved quantity
     ekin_before = iterative._compute_ekin()
     # Change the (selected) velocities
     if self.select is None:
         iterative.vel[:] = get_random_vel(self.temp, False, iterative.masses)
     else:
         iterative.vel[self.select] = get_random_vel(self.temp, False, iterative.masses, self.select)
     # Update the kinetic energy and the reference for the conserved quantity
     ekin_after = iterative._compute_ekin()
     self.econs_correction += ekin_before - ekin_after
     # Optional annealing
     self.temp *= self.annealing
Пример #2
0
 def pre(self, iterative, G1_add = None):
     # Andersen thermostat step before usual Verlet hook, since it largely affects the velocities
     # Needed to correct the conserved quantity
     ekin_before = iterative._compute_ekin()
     # Change the (selected) velocities
     if self.select is None:
         iterative.vel[:] = get_random_vel(self.temp, False, iterative.masses)
     else:
         iterative.vel[self.select] = get_random_vel(self.temp, False, iterative.masses, self.select)
     # Zero any external momenta after choosing new velocities
     clean_momenta(iterative.pos, iterative.vel, iterative.masses, iterative.ff.system.cell)
     # Update the kinetic energy and the reference for the conserved quantity
     ekin_after = iterative._compute_ekin()
     self.econs_correction += ekin_before - ekin_after
     # Optional annealing
     self.temp *= self.annealing
Пример #3
0
Файл: nvt.py Проект: boegel/yaff
 def pre(self, iterative, G1_add=None):
     # Andersen thermostat step before usual Verlet hook, since it largely affects the velocities
     # Needed to correct the conserved quantity
     ekin_before = iterative._compute_ekin()
     # Change the (selected) velocities
     if self.select is None:
         iterative.vel[:] = get_random_vel(self.temp, False,
                                           iterative.masses)
     else:
         iterative.vel[self.select] = get_random_vel(
             self.temp, False, iterative.masses, self.select)
     # Zero any external momenta after choosing new velocities
     clean_momenta(iterative.pos, iterative.vel, iterative.masses,
                   iterative.ff.system.cell)
     # Update the kinetic energy and the reference for the conserved quantity
     ekin_after = iterative._compute_ekin()
     self.econs_correction += ekin_before - ekin_after
     # Optional annealing
     self.temp *= self.annealing
Пример #4
0
    def __init__(self,
                 ff,
                 timestep=None,
                 state=None,
                 hooks=None,
                 vel0=None,
                 temp0=300,
                 scalevel0=True,
                 time0=None,
                 ndof=None,
                 counter0=None,
                 restart_h5=None):
        """
            **Arguments:**

            ff
                A ForceField instance

            **Optional arguments:**

            timestep
                The integration time step (in atomic units)

            state
                A list with state items. State items are simple objects
                that take or derive a property from the current state of the
                iterative algorithm.

            hooks
                A function (or a list of functions) that is called after every
                iterative.

            vel0
                An array with initial velocities. If not given, random
                velocities are sampled from the Maxwell-Boltzmann distribution
                corresponding to the optional arguments temp0 and scalevel0

            temp0
                The (initial) temperature for the random initial velocities

            scalevel0
                If True (the default), the random velocities are rescaled such
                that the instantaneous temperature coincides with temp0.

            time0
                The time associated with the initial state.

            ndof
                When given, this option overrides the number of degrees of
                freedom determined from internal heuristics. When ndof is not
                given, its default value depends on the thermostat used. In most
                cases it is 3*natom, except for the NHC thermostat where the
                number if internal degrees of freedom is counted. The ndof
                attribute is used to derive the temperature from the kinetic
                energy.

            counter0
                The counter value associated with the initial state.

            restart_h5
                HDF5 object containing the restart information
        """
        # Assign init arguments
        if timestep is None and restart_h5 is None:
            raise AssertionError('No Verlet timestep is found')
        self.ndof = ndof
        self.hooks = hooks
        self.restart_h5 = restart_h5

        # Retrieve the necessary properties if restarting. Restart objects
        # are overwritten by optional arguments in VerletIntegrator
        if self.restart_h5 is None:
            # set None variables to default value
            if time0 is None: time0 = 0.0
            if counter0 is None: counter0 = 0
            self.pos = ff.system.pos.copy()
            self.rvecs = ff.system.cell.rvecs.copy()
            self.timestep = timestep
            self.time = time0
        else:
            # Arguments associated with the unit cell and positions are always retrieved
            tgrp = self.restart_h5['trajectory']
            self.pos = tgrp['pos'][-1, :, :]
            ff.update_pos(self.pos)
            if 'cell' in tgrp:
                self.rvecs = tgrp['cell'][-1, :, :]
                ff.update_rvecs(self.rvecs)
            else:
                self.rvecs = None
            # Arguments which can be provided in the VerletIntegrator object are only
            # taken from the restart file if not provided explicitly
            if time0 is None:
                self.time = tgrp['time'][-1]
            else:
                self.time = time0
            if counter0 is None:
                counter0 = tgrp['counter'][-1]
            if vel0 is None:
                vel0 = tgrp['vel'][-1, :, :]
            if timestep is None:
                self.timestep = self.restart_h5['/restart/timestep'][()]
            self._restart_add_hooks(self.restart_h5, ff)

        # Verify the hooks: combine thermostat and barostat if present
        self._verify_hooks()

        # The integrator needs masses. If not available, take default values.
        if ff.system.masses is None:
            ff.system.set_standard_masses()
        self.masses = ff.system.masses

        # Set random initial velocities if needed.
        if vel0 is None:
            self.vel = get_random_vel(temp0, scalevel0, self.masses)
        else:
            self.vel = vel0.copy()

        # Working arrays
        self.gpos = np.zeros(self.pos.shape, float)
        self.delta = np.zeros(self.pos.shape, float)
        self.vtens = np.zeros((3, 3), float)

        # Tracks quality of the conserved quantity
        self._cons_err_tracker = ConsErrTracker(restart_h5)
        Iterative.__init__(self, ff, state, self.hooks, counter0)
Пример #5
0
    def __init__(self, ff, timestep, state=None, hooks=None, vel0=None,
                 temp0=300, scalevel0=True, time0=0.0, ndof=None, counter0=0):
        """
           **Arguments:**

           ff
                A ForceField instance

           timestep
                The integration time step (in atomic units)

           **Optional arguments:**

           state
                A list with state items. State items are simple objects
                that take or derive a property from the current state of the
                iterative algorithm.

           hooks
                A function (or a list of functions) that is called after every
                iterative.

           vel0
                An array with initial velocities. If not given, random
                velocities are sampled from the Maxwell-Boltzmann distribution
                corresponding to the optional arguments temp0 and scalevel0

           temp0
                The (initial) temperature for the random initial velocities

           scalevel0
                If True (the default), the random velocities are rescaled such
                that the instantaneous temperature coincides with temp0.

           time0
                The time associated with the initial state.

           ndof
                When given, this option overrides the number of degrees of
                freedom determined from internal heuristics. When ndof is not
                given, its default value depends on the thermostat used. In most
                cases it is 3*natom, except for the NHC thermostat where the
                number if internal degrees of freedom is counted. The ndof
                attribute is used to derive the temperature from the kinetic
                energy.

           counter0
                The counter value associated with the initial state.
        """
        # Assign init arguments
        self.pos = ff.system.pos.copy()
        self.timestep = timestep
        self.time = time0
        self.ndof = ndof

        # The integrator needs masses. If not available, take default values.
        if ff.system.masses is None:
            ff.system.set_standard_masses()
        self.masses = ff.system.masses

        # Set random initial velocities if needed.
        if vel0 is None:
            self.vel = get_random_vel(temp0, scalevel0, self.masses)
        else:
            self.vel = vel0.copy()

        # Working arrays
        self.gpos = np.zeros(self.pos.shape, float)
        self.delta = np.zeros(self.pos.shape, float)
        self.vtens = np.zeros((3, 3), float)

        # Tracks quality of the conserved quantity
        self._cons_err_tracker = ConsErrTracker()

        Iterative.__init__(self, ff, state, hooks, counter0)
Пример #6
0
    def __init__(self, ff, timestep=None, state=None, hooks=None, vel0=None,
                 temp0=300, scalevel0=True, time0=None, ndof=None, counter0=None, restart_h5=None):
        """
            **Arguments:**

            ff
                A ForceField instance

            **Optional arguments:**

            timestep
                The integration time step (in atomic units)

            state
                A list with state items. State items are simple objects
                that take or derive a property from the current state of the
                iterative algorithm.

            hooks
                A function (or a list of functions) that is called after every
                iterative.

            vel0
                An array with initial velocities. If not given, random
                velocities are sampled from the Maxwell-Boltzmann distribution
                corresponding to the optional arguments temp0 and scalevel0

            temp0
                The (initial) temperature for the random initial velocities

            scalevel0
                If True (the default), the random velocities are rescaled such
                that the instantaneous temperature coincides with temp0.

            time0
                The time associated with the initial state.

            ndof
                When given, this option overrides the number of degrees of
                freedom determined from internal heuristics. When ndof is not
                given, its default value depends on the thermostat used. In most
                cases it is 3*natom, except for the NHC thermostat where the
                number if internal degrees of freedom is counted. The ndof
                attribute is used to derive the temperature from the kinetic
                energy.

            counter0
                The counter value associated with the initial state.

            restart_h5
                HDF5 object containing the restart information
        """
        # Assign init arguments
        if timestep is None and restart_h5 is None:
            raise AssertionError('No Verlet timestep is found')
        self.ndof = ndof
        self.hooks = hooks
        self.restart_h5 = restart_h5

        # Retrieve the necessary properties if restarting. Restart objects
        # are overwritten by optional arguments in VerletIntegrator
        if self.restart_h5 is None:
            # set None variables to default value
            if time0 is None: time0 = 0.0
            if counter0 is None: counter0 = 0
            self.pos = ff.system.pos.copy()
            self.rvecs = ff.system.cell.rvecs.copy()
            self.timestep = timestep
            self.time = time0
        else:
            # Arguments associated with the unit cell and positions are always retrieved
            tgrp = self.restart_h5['trajectory']
            self.pos = tgrp['pos'][-1,:,:]
            ff.update_pos(self.pos)
            if 'cell' in tgrp:
                self.rvecs = tgrp['cell'][-1,:,:]
                ff.update_rvecs(self.rvecs)
            else:
                self.rvecs = None
            # Arguments which can be provided in the VerletIntegrator object are only
            # taken from the restart file if not provided explicitly
            if time0 is None:
                self.time = tgrp['time'][-1]
            else:
                self.time = time0
            if counter0 is None:
                counter0 = tgrp['counter'][-1]
            if vel0 is None:
                vel0 = tgrp['vel'][-1,:,:]
            if timestep is None:
                self.timestep = self.restart_h5['/restart/timestep'][()]
            self._restart_add_hooks(self.restart_h5, ff)

        # Verify the hooks: combine thermostat and barostat if present
        self._verify_hooks()

        # The integrator needs masses. If not available, take default values.
        if ff.system.masses is None:
            ff.system.set_standard_masses()
        self.masses = ff.system.masses

        # Set random initial velocities if needed.
        if vel0 is None:
            self.vel = get_random_vel(temp0, scalevel0, self.masses)
        else:
            self.vel = vel0.copy()

        # Working arrays
        self.gpos = np.zeros(self.pos.shape, float)
        self.delta = np.zeros(self.pos.shape, float)
        self.vtens = np.zeros((3, 3), float)

        # Tracks quality of the conserved quantity
        self._cons_err_tracker = ConsErrTracker(restart_h5)
        Iterative.__init__(self, ff, state, self.hooks, counter0)