예제 #1
0
파일: io.py 프로젝트: boegel/yaff
    def __init__(self, f, start=0, step=1000, flush=None):
        """
            **Argument:**

            f
                A h5.File object to write the restart information to.

            **Optional arguments:**

            start
                The first iteration at which this hook should be called.

            step
                The hook will be called every `step` iterations.

            flush
                Flush the h5.File object every `flush` iterations so it can be
                read up to the latest flush. This is useful to avoid data loss
                for long calculations or to monitor running calculations.
                Note that flushing too often might impact performance of hdf5.
        """
        self.f = f
        self.flush = flush
        self.state = None
        self.default_state = None
        Hook.__init__(self, start, step)
예제 #2
0
    def __init__(self, start=0, step=1):
        """
           **Optional arguments:**

           start
                The first iteration at which this hook should be called.

           step
                The hook will be called every `step` iterations.
        """
        self.econs_correction = 0.0
        Hook.__init__(self, start=0, step=1)
예제 #3
0
파일: verlet.py 프로젝트: tovrstra/yaff
    def __init__(self, start=0, step=1):
        """
           **Optional arguments:**

           start
                The first iteration at which this hook should be called.

           step
                The hook will be called every `step` iterations.
        """
        self.econs_correction = 0.0
        Hook.__init__(self, start=0, step=1)
예제 #4
0
    def __init__(self, f, start=0, step=1):
        """
           **Argument:**

           f
                A h5.File object to write the trajectory to.

           **Optional arguments:**

           start
                The first iteration at which this hook should be called.

           step
                The hook will be called every `step` iterations.
        """
        self.f = f
        Hook.__init__(self, start, step)
예제 #5
0
    def __init__(self, f, start=0, step=1000):
        """
            **Argument:**

            f
                A h5.File object to write the restart information to.

            **Optional arguments:**

            start
                The first iteration at which this hook should be called.

            step
                The hook will be called every `step` iterations.
        """
        self.f = f
        self.state = None
        self.default_state = None
        Hook.__init__(self, start, step)
예제 #6
0
    def __init__(self, fn_xyz, select=None, start=0, step=1):
        """
           **Argument:**

           fn_xyz
                A filename to write the XYZ trajectory too.

           **Optional arguments:**

           select
                A list of atom indexes that should be written to the trajectory
                output. If not given, all atoms are included.

           start
                The first iteration at which this hook should be called.

           step
                The hook will be called every `step` iterations.
        """
        self.fn_xyz = fn_xyz
        self.select = select
        self.xyz_writer = None
        Hook.__init__(self, start, step)
예제 #7
0
파일: io.py 프로젝트: tovrstra/yaff
    def __init__(self, fn_xyz, select=None, start=0, step=1):
        """
           **Argument:**

           fn_xyz
                A filename to write the XYZ trajectory too.

           **Optional arguments:**

           select
                A list of atom indexes that should be written to the trajectory
                output. If not given, all atoms are included.

           start
                The first iteration at which this hook should be called.

           step
                The hook will be called every `step` iterations.
        """
        self.fn_xyz = fn_xyz
        self.select = select
        self.xyz_writer = None
        Hook.__init__(self, start, step)
예제 #8
0
파일: io.py 프로젝트: tovrstra/yaff
    def __init__(self, f, start=0, step=1, flush=None):
        """
           **Argument:**

           f
                A h5.File object to write the trajectory to.

           **Optional arguments:**

           start
                The first iteration at which this hook should be called.

           step
                The hook will be called every `step` iterations.

           flush
                Flush the h5.File object every `flush` iterations so it can be
                read up to the latest flush. This is useful to avoid data loss
                for long calculations or to monitor running calculations.
                Note that flushing too often might impact performance of hdf5.
        """
        self.f = f
        self.flush = flush
        Hook.__init__(self, start, step)
예제 #9
0
파일: opt.py 프로젝트: tovrstra/yaff
 def __init__(self, start=0, step=1):
     Hook.__init__(self, start, step)
     self.time0 = None
예제 #10
0
 def __init__(self, start=0, step=1):
     Hook.__init__(self, start, step)
     self.time0 = None
예제 #11
0
    def __init__(self, ff, cv, sigma, K, f=None, start=0, step=1,
                 restart_file=None, tempering=0, periodicities=None, comlist=None):
        """
           **Arguments:**

           ff
                A ForceField instance

           cv
                A single ``CollectiveVariable`` or a list of ``CollectiveVariable``
                instances.

           sigma
                The width of the Gaussian or a NumPy array [Ncv] specifying the
                widths of the Gaussians

           K
                The prefactor of the Gaussian hills.

           **Optional arguments:**

           f
                A h5.File object to write the Gaussian hills to.

           start
                The first iteration at which a Gaussian hill should be added.

           step
                A Gaussian hill will be added every `step` iterations.

           restart_files
                A single h5 file containing hills added during previous
                simulations. Gaussian hills present in restart_files will
                be added at the start of the simulation.

           tempering
                Perform a well-tempered metadynamics simulation

           periodicities
                The periodicity of the single collective variable or a [Ncv]
                NumPy array specifying the periodicity of each
                collective variable. Specifying None means the CV is not
                periodic.

           comlist
                An optional layer to derive centers of mass from the atomic positions.
                These centers of mass are used as input for the first layer, the relative
                vectors.
        """
        self.hills = GaussianHills(cv, sigma, periodicities=periodicities)
        self.K = K
        self.f = f
        self.tempering = tempering
        # Add the bias part to the force field
        part = ForcePartBias(ff.system, comlist=comlist)
        part.add_term(self.hills)
        ff.add_part(part)
        # Initialize hills from restart files
        if restart_file is not None:
            if not 'hills' in restart_file:
                raise ValueError("Could not read hills group from %s"%(restart_file))
            if not self.tempering==restart_file['hills'].attrs['tempering']:
                raise ValueError("Inconsistent tempering between runs")
            if 'hills/periodicities' in restart_file:
                if not np.all(self.hills.periodicities==restart_file['hills/periodicities']):
                    raise ValueError("Inconsistent periodicities between runs")
            elif self.hills.periodicities is not None:
                raise ValueError("Inconsistent periodicities between runs")
            q0 = restart_file['hills/q0'][:]
            K = restart_file['hills/K'][:]
            self.hills.add_hills(q0, K)
            if self.f is not None:
                for istep in range(q0.shape[0]):
                    self.dump_h5(q0[istep], K[istep])
        Hook.__init__(self, start, step)
예제 #12
0
    def __init__(self,
                 system,
                 timestep=0.0,
                 restart=0,
                 fn='plumed.dat',
                 kernel=None,
                 fn_log='plumed.log'):
        r'''Initialize a PLUMED ForcePart. More information on the interface
            between PLUMED and MD codes can be found on
            http://tcb.ucas.ac.cn/plumed2/developer-doc/html/_how_to_plumed_your_m_d.html

            Unfortunately, PLUMED partially breaks the orthogonality of the pes
            and the sampling modules in Yaff: PLUMED sometimes requires
            information from the integrator. For example, in metadynamics
            PLUMED needs to know when a time integration step has been
            completed (which is not necessarily after each force calculation).
            ForcePartPlumed therefore also inherits from Hook and
            by attaching this hook to the integrator, it is possible to obtain
            the necessary information from the integrator. Problems within
            PLUMED for this approach to work, particularly in the VES module,
            have been resolved; see the discussion at
            https://groups.google.com/forum/?fromgroups=#!topic/plumed-users/kPZu_tNZtgk

            **Arguments:**

            system
                An instance of the System class

            **Optional Arguments:**

            timestep
                The timestep (in au) of the integrator

            restart
                Set to a value different from 0 to let PLUMED know that this
                is a restarted run

            fn
                A filename from which the PLUMED instructions are read, default
                is plumed.dat

            kernel
                Path to the PLUMED library (something like
                /path/to/libplumedKernel.so). If None is provided, the
                environment variable $PLUMED_KERNEL should point to the library
                file.

            fn_log
                Path to the file where PLUMED logs output, default is
                plumed.log
        '''
        self.system = system
        self.fn = fn
        self.kernel = kernel
        self.fn_log = fn_log
        self.plumedstep = 0
        # TODO In the LAMMPS-PLUMED interface (src/USER-PLUMED/fix_plumed.cpp)
        # it is mentioned that biasing is not possible when tailcorrections are
        # included. Maybe this should be checked...
        # Check cell dimensions, only 0D and 3D systems supported
        if not self.system.cell.nvec in [0, 3]:
            raise NotImplementedError
        # Setup PLUMED by sending commands to the PLUMED API
        self.setup_plumed(timestep, restart)
        # PLUMED requires masses to be set...
        if self.system.masses is None:
            self.system.set_standard_masses()
        # Initialize the ForcePart
        ForcePart.__init__(self, 'plumed', self.system)
        # Initialize the Hook, can't see a reason why start and step could
        # differ from default values
        Hook.__init__(self, start=0, step=1)
        self.hooked = False
        if log.do_warning:
            log.warn("When using PLUMED as a hook for your integrator "
                     "and PLUMED adds time-dependent forces (for instance "
                     "when performing metadynamics), there is no energy "
                     "conservation. The conserved quantity reported by "
                     "YAFF is irrelevant in this case.")