예제 #1
0
파일: __init__.py 프로젝트: s-dale/pyIID
 def __init__(self,
              atoms,
              restart=None,
              logfile=None,
              trajectory=None,
              seed=None,
              verbose=False):
     Optimizer.__init__(self, atoms, restart, logfile, trajectory=None)
     atoms.get_forces()
     atoms.get_potential_energy()
     if seed is None:
         seed = np.random.randint(0, 2**31)
     self.verbose = verbose
     self.random_state = RandomState(seed)
     self.starting_atoms = dc(atoms)
     self.pe = []
     self.metadata = {'seed': seed}
     self.traj = [dc(atoms)]
     print(self.traj[0].get_momenta())
     if trajectory is not None:
         self.trajectory = Trajectory(trajectory, mode='w')
         self.trajectory.write(self.traj[-1])
         if self.verbose:
             print('Trajectory written', len(self.traj))
     else:
         self.trajectory = None
     if verbose:
         print('trajectory file', self.trajectory)
예제 #2
0
파일: bfgs.py 프로젝트: rosswhitfield/ase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 maxstep=0.04, master=None):
        """BFGS optimizer.

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.04 Å).

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
        if maxstep > 1.0:
            warnings.warn('You are using a much too large value for '
                          'the maximum step size: %.1f Å' % maxstep)
        self.maxstep = maxstep

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)
예제 #3
0
파일: sciopt.py 프로젝트: rosswhitfield/ase
    def __init__(self, atoms, logfile="-", trajectory=None, callback_always=False, alpha=70.0, master=None):
        """Initialize object

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.
        
        callback_always: book
            Should the callback be run after each force call (also in the
            linesearch)

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
        restart = None
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)
        self.force_calls = 0
        self.callback_always = callback_always
        self.H0 = alpha
예제 #4
0
파일: bfgs.py 프로젝트: lqcata/ase
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 maxstep=None):
        """BFGS optimizer.

        Parameters:

        restart: string
            Pickle file used to store hessian matrix. If set, file with 
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.
        trajectory: string
            Pickle file used to store trajectory of atomic movement.
        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.04 Å).
        """

        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        if maxstep is not None:
            if maxstep > 1.0:
                raise ValueError('You are using a much too large value for ' +
                                 'the maximum step size: %.1f Å' % maxstep)
            self.maxstep = maxstep
예제 #5
0
파일: mdmin.py 프로젝트: misdoro/python-ase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 dt=None, master=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).

        logfile: string
            Text file used to write summary information.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        if dt is not None:
            self.dt = dt
예제 #6
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 dt=0.1, maxmove=0.2, dtmax=1.0, Nmin=5, finc=1.1, fdec=0.5,
                 astart=0.1, fa=0.99, a=0.1, master=None, downhill_check=False,
                 position_reset_callback=None, force_consistent=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        downhill_check: boolean
            Downhill check directly compares potential energies of subsequent
            steps of the FIRE algorithm rather than relying on the current
            product v*f that is positive if the FIRE dynamics moves downhill.
            This can detect numerical issues where at large time steps the step
            is uphill in energy even though locally v*f is positive, i.e. the
            algorithm jumps over a valley because of a too large time step.

        position_reset_callback: function(atoms, r, e, e_last)
            Function that takes current *atoms* object, an array of position
            *r* that the optimizer will revert to, current energy *e* and
            energy of last step *e_last*. This is only called if e > e_last.

        force_consistent: boolean or None
            Use force-consistent energy calls (as opposed to the energy
            extrapolated to 0 K).  By default (force_consistent=None) uses
            force-consistent energies if available in the calculator, but
            falls back to force_consistent=False if not.  Only meaningful
            when downhill_check is True.
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory,
                           master, force_consistent=force_consistent)

        self.dt = dt
        self.Nsteps = 0
        self.maxmove = maxmove
        self.dtmax = dtmax
        self.Nmin = Nmin
        self.finc = finc
        self.fdec = fdec
        self.astart = astart
        self.fa = fa
        self.a = a
        self.downhill_check = downhill_check
        self.position_reset_callback = position_reset_callback
예제 #7
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 master=None, force_consistent=False, irctol=1e-3, dx=0.1,
                 eta=1e-4, gamma=0.4, peskwargs=None, **kwargs):
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master,
                           force_consistent)
        self.irctol = irctol
        self.dx = dx
        if peskwargs is None:
            self.peskwargs = dict(gamma=gamma)

        if 'masses' not in self.atoms.arrays:
            try:
                self.atoms.set_masses('most_common')
            except ValueError:
                warnings.warn("The version of ASE that is installed does not "
                              "contain the most common isotope masses, so "
                              "Earth-abundance-averaged masses will be used "
                              "instead!")
                self.atoms.set_masses('defaults')

        self.sqrtm = np.repeat(np.sqrt(self.atoms.get_masses()), 3)

        def get_W(self):
            return np.diag(1. / np.sqrt(np.repeat(self.atoms.get_masses(), 3)))
        PES.get_W = get_W
        self.pes = PES(atoms, eta=eta, proj_trans=False, proj_rot=False,
                       **kwargs)

        self.lastrun = None
        self.x0 = self.pes.get_x()
        self.v0ts = None
        self.H0 = None
        self.peslast = None
        self.xi = 1.
        self.first = True
예제 #8
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 dt=None, master=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).

        logfile: string
            Text file used to write summary information.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        if dt is not None:
            self.dt = dt
예제 #9
0
파일: irc.py 프로젝트: kevinmooreiii/ase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 stepsize=5., master=None):
        """IRC optimizer.

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.
        
        stepsize: 
            Step size taken in Bohr 
            
        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """

        self.stepsize = stepsize
        self.maxiter = maxiter

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)
예제 #10
0
파일: sciopt.py 프로젝트: lqcata/ase
    def __init__(self,
                 atoms,
                 logfile='-',
                 trajectory=None,
                 callback_always=False,
                 alpha=70.0):
        """Initialize object

        Parameters:

        callback_always: book
            Should the callback be run after each force call (also in the
            linesearch)

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.

        """
        restart = None
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
        self.force_calls = 0
        self.callback_always = callback_always
        self.H0 = alpha
예제 #11
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 maxstep=.2,
                 trajectory=None,
                 c1=0.23,
                 c2=0.46,
                 alpha=10.0,
                 stpmax=50.0,
                 master=None):
        """Optimize atomic positions in the BFGSLineSearch algorithm, which
        uses both forces and potential energy information.

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.
        
        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).
        
        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
        self.maxstep = maxstep
        self.stpmax = stpmax
        self.alpha = alpha
        self.H = None
        self.c1 = c1
        self.c2 = c2
        self.force_calls = 0
        self.function_calls = 0
        self.r0 = None
        self.g0 = None
        self.e0 = None
        self.load_restart = False
        self.task = 'START'
        self.rep_count = 0
        self.p = None
        self.alpha_k = None
        self.no_update = False
        self.replay = False

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)
예제 #12
0
    def __init__(self, atoms, restart=None, logfile='-', maxstep=.2,
                 trajectory=None, c1=0.23, c2=0.46, alpha=10.0, stpmax=50.0,
                 master=None, force_consistent=None):
        """Optimize atomic positions in the BFGSLineSearch algorithm, which
        uses both forces and potential energy information.

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        force_consistent: boolean or None
            Use force-consistent energy calls (as opposed to the energy
            extrapolated to 0 K).  By default (force_consistent=None) uses
            force-consistent energies if available in the calculator, but
            falls back to force_consistent=False if not.
        """
        self.maxstep = maxstep
        self.stpmax = stpmax
        self.alpha = alpha
        self.H = None
        self.c1 = c1
        self.c2 = c2
        self.force_calls = 0
        self.function_calls = 0
        self.r0 = None
        self.g0 = None
        self.e0 = None
        self.load_restart = False
        self.task = 'START'
        self.rep_count = 0
        self.p = None
        self.alpha_k = None
        self.no_update = False
        self.replay = False

        Optimizer.__init__(self, atoms, restart, logfile, trajectory,
                           master, force_consistent)
예제 #13
0
파일: lbfgs.py 프로젝트: PHOTOX/fuase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 maxstep=None, memory=100, damping=1.0, alpha=70.0,
                 use_line_search=False):
        """
        Parameters:

        restart: string
            Pickle file used to store vectors for updating the inverse of
            Hessian matrix. If set, file with such a name will be searched
            and information stored will be used, if the file exists.

        logfile: string
            Where should output go. None for no output, '-' for stdout.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            How far is a single atom allowed to move. This is useful for DFT
            calculations where wavefunctions can be reused if steps are small.
            Default is 0.04 Angstrom.

        memory: int
            Number of steps to be stored. Default value is 100. Three numpy
            arrays of this length containing floats are stored.

        damping: float
            The calculated step is multiplied with this number before added to
            the positions.

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.
            
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        if maxstep is not None:
            if maxstep > 1.0:
                raise ValueError('You are using a much too large value for ' +
                                 'the maximum step size: %.1f Angstrom' %
                                 maxstep)
            self.maxstep = maxstep
        else:
            self.maxstep = 0.04

        self.memory = memory
        self.H0 = 1. / alpha  # Initial approximation of inverse Hessian
                            # 1./70. is to emulate the behaviour of BFGS
                            # Note that this is never changed!
        self.damping = damping
        self.use_line_search = use_line_search
        self.p = None
        self.function_calls = 0
        self.force_calls = 0
예제 #14
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 master=None,
                 force_consistent=False,
                 delta0=1.3e-3,
                 sigma_inc=1.15,
                 sigma_dec=0.65,
                 rho_dec=5.0,
                 rho_inc=1.035,
                 order=1,
                 eig=True,
                 eta=1e-4,
                 peskwargs=None,
                 method='rsprfo',
                 gamma=0.4,
                 constraints_tol=1e-5,
                 **kwargs):
        Optimizer.__init__(self, atoms, restart, logfile, None, master,
                           force_consistent)
        self.pes = PESWrapper(atoms,
                              atoms.calc,
                              trajectory=trajectory,
                              **kwargs)
        self.delta = delta0 * len(self.pes.x_m)
        self.sigma_inc = sigma_inc
        self.sigma_dec = sigma_dec
        self.rho_inc = rho_inc
        self.rho_dec = rho_dec
        self.ord = order
        self.eig = eig
        self.eta = eta
        self.delta_min = self.eta
        self.constraints_tol = constraints_tol
        self.niter = 0
        if peskwargs is None:
            self.peskwargs = dict(eta=self.eta, gamma=gamma)
        else:
            self.peskwargs = peskwargs
            if 'eta' not in self.peskwargs:
                self.peskwargs['eta'] = self.eta
            if 'gamma' not in self.peskwargs:
                self.peskwargs['gamma'] = gamma

        if self.ord != 0 and not self.eig:
            warnings.warn("Saddle point optimizations with eig=False will "
                          "most likely fail!\n Proceeding anyway, but you "
                          "shouldn't be optimistic.")

        self.initialized = False
        self.xi = 1.
        self.method = method
        if self.method not in ['gmtrm', 'rsrfo', 'rsprfo']:
            raise ValueError('Unknown method:', method)
예제 #15
0
파일: lbfgs.py 프로젝트: slabanja/ase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 maxstep=None, memory=100, damping = 1.0, alpha = 10.0,
                 use_line_search=False):
        """
        Parameters:

        restart: string
            Pickle file used to store vectors for updating the inverse of Hessian
            matrix. If set, file with such a name will be searched and information
            stored will be used, if the file exists.

        logfile: string
            Where should output go. None for no output, '-' for stdout.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            How far is a single atom allowed to move. This is useful for DFT
            calculations where wavefunctions can be reused if steps are small.
            Default is 0.04 Angstrom.

        memory: int
            Number of steps to be stored. Default value is 100. Three numpy
            arrays of this length containing floats are stored.

        damping: float
            The calculated step is multiplied with this number before added to
            the positions. 

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.
            
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        if maxstep is not None:
            if maxstep > 1.0:
                raise ValueError('You are using a much too large value for ' +
                                 'the maximum step size: %.1f Angstrom' % maxstep)
            self.maxstep = maxstep
        else:
            self.maxstep = 0.04

        self.memory = memory
        self.H0 = 1. / alpha  # Initial approximation of inverse Hessian
                            # 1./70. is to emulate the behaviour of BFGS
                            # Note that this is never changed!
        self.damping = damping
        self.use_line_search = use_line_search
        self.p = None
        self.function_calls = 0
        self.force_calls = 0
예제 #16
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 maxstep=None,
                 master=None,
                 alpha=None):
        """BFGS optimizer.

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Å).

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.
        """
        if maxstep is None:
            self.maxstep = self.defaults['maxstep']
        else:
            self.maxstep = maxstep

        if self.maxstep > 1.0:
            warnings.warn('You are using a *very* large value for '
                          'the maximum step size: %.1f Å' % maxstep)

        if alpha is None:
            self.alpha = self.defaults['alpha']
        else:
            self.alpha = alpha

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)
예제 #17
0
파일: mdmin.py 프로젝트: lqcata/ase
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 dt=None):
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        if dt is not None:
            self.dt = dt
예제 #18
0
    def __init__(self,
                 atoms,
                 logfile='-',
                 trajectory=None,
                 callback_always=False,
                 alpha=70.0,
                 master=None,
                 force_consistent=None):
        """Initialize object

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        callback_always: book
            Should the callback be run after each force call (also in the
            linesearch)

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        force_consistent: boolean or None
            Use force-consistent energy calls (as opposed to the energy
            extrapolated to 0 K).  By default (force_consistent=None) uses
            force-consistent energies if available in the calculator, but
            falls back to force_consistent=False if not.
        """
        restart = None
        Optimizer.__init__(self,
                           atoms,
                           restart,
                           logfile,
                           trajectory,
                           master,
                           force_consistent=force_consistent)
        self.force_calls = 0
        self.callback_always = callback_always
        self.H0 = alpha
예제 #19
0
    def __init__(self, atoms, logfile='-', trajectory=None,
                 callback_always=False):
        """Parameters:

        callback_always: book
            Should the callback be run after each force call (also in the
            linesearch)
        """
        restart = None
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
        self.function_calls = 0
        self.callback_always = callback_always
예제 #20
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 dt=0.1, maxmove=0.2, dtmax=1.0, Nmin=5, finc=1.1, fdec=0.5,
                 astart=0.1, fa=0.99, a=0.1, theta=0.1, master=None,
                 precon=None, use_armijo=True, variable_cell=False):
        """
        Preconditioned version of the FIRE optimizer

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: bool
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        variable_cell: bool
            If True, wrap atoms in UnitCellFilter to relax cell and positions.

        In time this implementation is expected to replace
        ase.optimize.fire.FIRE.
        """
        if variable_cell:
            atoms = UnitCellFilter(atoms)
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        self.dt = dt
        self.Nsteps = 0
        self.maxmove = maxmove
        self.dtmax = dtmax
        self.Nmin = Nmin
        self.finc = finc
        self.fdec = fdec
        self.astart = astart
        self.fa = fa
        self.a = a
        self.theta = theta
        self.precon = precon
        self.use_armijo = use_armijo
예제 #21
0
파일: __init__.py 프로젝트: ZhouHUB/pyIID
 def __init__(self, atoms, restart=None, logfile=None, trajectory=None,
              seed=None,
              verbose=False):
     Optimizer.__init__(self, atoms, restart, logfile, trajectory)
     atoms.get_forces()
     atoms.get_potential_energy()
     if seed is None:
         seed = np.random.randint(0, 2 ** 31)
     self.verbose = verbose
     self.random_state = RandomState(seed)
     self.starting_atoms = dc(atoms)
     self.traj = [dc(atoms)]
     self.pe = []
     self.metadata = {'seed': seed}
예제 #22
0
파일: fire.py 프로젝트: lqcata/ase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 dt=0.1, maxmove=0.2, dtmax=1.0, Nmin=5, finc=1.1, fdec=0.5,
                 astart=0.1, fa=0.99, a=0.1):
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        self.dt = dt
        self.Nsteps = 0
        self.maxmove = maxmove
        self.dtmax = dtmax
        self.Nmin = Nmin
        self.finc = finc
        self.fdec = fdec
        self.astart = astart
        self.fa = fa
        self.a = a
예제 #23
0
파일: sciopt.py 프로젝트: lqcata/ase
    def __init__(self,
                 atoms,
                 logfile='-',
                 trajectory=None,
                 callback_always=False):
        """Parameters:

        callback_always: book
            Should the callback be run after each force call (also in the
            linesearch)
        """
        restart = None
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
        self.function_calls = 0
        self.callback_always = callback_always
예제 #24
0
    def irun(self, fmax=0.05, steps=None, direction='forward'):
        if direction not in ['forward', 'reverse']:
            raise ValueError('direction must be one of "forward" or '
                             '"reverse"!')

        if self.v0ts is None:
            # Initial diagonalization
            self.pes.diag(**self.peskwargs)
            Hw = self.pes.get_H().asarray() / np.outer(self.sqrtm, self.sqrtm)
            _, vecs = eigh(Hw)
            self.v0ts = self.dx * vecs[:, 0] / self.sqrtm
            self.H0 = self.pes.get_H().asarray().copy()
            self.pescurr = self.pes.curr.copy()
            self.peslast = self.pes.last.copy()
        else:
            # Or, restore from last diagonalization for new direction
            self.pes.set_x(self.x0.copy())
            self.pes.set_H(self.H0.copy())
            self.pes.curr = self.pescurr.copy()
            self.pes.last = self.peslast.copy()

        if direction == 'forward':
            self.d1 = self.v0ts.copy()
        elif direction == 'reverse':
            self.d1 = -self.v0ts.copy()

        self.first = True
        return Optimizer.irun(self, fmax, steps)
예제 #25
0
파일: oldqn.py 프로젝트: lqcata/ase
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 fmax=None,
                 converged=None,
                 hessianupdate='BFGS',
                 hessian=None,
                 forcemin=True,
                 verbosity=None,
                 maxradius=None,
                 diagonal=20.,
                 radius=None,
                 transitionstate=False):

        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        self.eps = 1e-12
        self.hessianupdate = hessianupdate
        self.forcemin = forcemin
        self.verbosity = verbosity
        self.diagonal = diagonal

        self.atoms = atoms

        n = len(self.atoms) * 3
        if radius is None:
            self.radius = 0.05 * np.sqrt(n) / 10.0
        else:
            self.radius = radius

        if maxradius is None:
            self.maxradius = 0.5 * np.sqrt(n)
        else:
            self.maxradius = maxradius

        # 0.01 < radius < maxradius
        self.radius = max(min(self.radius, self.maxradius), 0.0001)

        self.transitionstate = transitionstate

        # check if this is a nudged elastic band calculation
        if hasattr(atoms, 'springconstant'):
            self.forcemin = False

        self.t0 = time.time()
예제 #26
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 maxstep=.2,
                 trajectory=None,
                 c1=0.23,
                 c2=0.46,
                 alpha=10.0,
                 stpmax=50.0):
        """Optimize atomic positions in the BFGSLineSearch algorithm, which
        uses both forces and potential energy information.

        Parameters:

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.
        trajectory: string
            Pickle file used to store trajectory of atomic movement.
        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).
        logfile: string
            Text file used to write summary information.
        """
        self.maxstep = maxstep
        self.stpmax = stpmax
        self.alpha = alpha
        self.H = None
        self.c1 = c1
        self.c2 = c2
        self.force_calls = 0
        self.function_calls = 0
        self.r0 = None
        self.g0 = None
        self.e0 = None
        self.load_restart = False
        self.task = 'START'
        self.rep_count = 0
        self.p = None
        self.alpha_k = None
        self.no_update = False
        self.replay = False

        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
예제 #27
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 maxstep=.2,
                 trajectory=None,
                 c1=.23,
                 c2=0.46,
                 alpha=10.,
                 stpmax=50.,
                 use_free_energy=True):
        """Minimize a function using the BFGS algorithm.

        Notes:

            Optimize the function, f, whose gradient is given by fprime
            using the quasi-Newton method of Broyden, Fletcher, Goldfarb,
            and Shanno (BFGS) See Wright, and Nocedal 'Numerical
            Optimization', 1999, pg. 198.

        *See Also*:

          scikits.openopt : SciKit which offers a unified syntax to call
                            this and other solvers.

        """
        self.maxstep = maxstep
        self.stpmax = stpmax
        self.alpha = alpha
        self.H = None
        self.c1 = c1
        self.c2 = c2
        self.force_calls = 0
        self.function_calls = 0
        self.r0 = None
        self.g0 = None
        self.e0 = None
        self.load_restart = False
        self.task = 'START'
        self.rep_count = 0
        self.p = None
        self.alpha_k = None
        self.no_update = False
        self.replay = False
        self.use_free_energy = use_free_energy

        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
예제 #28
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 maxstep=None,
                 master=None):
        """BFGS optimizer.

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Å).

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
        if maxstep is not None:
            self.maxstep = maxstep
        else:
            self.maxstep = defaults.maxstep

        if self.maxstep > 1.0:
            warnings.warn('You are using a much too large value for '
                          'the maximum step size: %.1f Å' % maxstep)

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)
예제 #29
0
 def __init__(self,
              atoms,
              restart=None,
              logfile='-',
              trajectory=None,
              master=None,
              variable_cell=False,
              optimizer='JuLIP.Solve.ConjugateGradient'):
     """Parameters:
     atoms: Atoms object
         The Atoms object to relax.
     restart, logfile ,trajector master : as for ase.optimize.optimize.Optimzer
     variable_cell : bool
         If true optimize the cell degresses of freedom as well as the
         atomic positions. Default is False.
     """
     Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)
     self.optimizer = Main.eval(optimizer)
     self.variable_cell = variable_cell
예제 #30
0
파일: IRC.py 프로젝트: zhoutf/ASE_ANI
    def __init__(self, atoms, stride=0.1, hessian=None, search_vector=None, forward=True, mw=True,
                 restart=None, logfile='-', trajectory=None, master=None):
        """IRC with Gonsalez-Schlegel method
        
        Parameters:
        
        atoms: Atoms object
        
        stride: step radius
        
        hessian: Hessian matrix in cartesian coordinates. Will be calculates if not given, 
                 or search_vector will be used instead. 
                 Will use first eigenvector of hessian, should be negative  
             
        search_vector: initial step direction, in cartesian coordinates
        
        forward: positive or negative direction along search vector
        
        mw: do search in mass-weighted (IRC) or cartesian (MEP) coordinates
        """

        self.stride = stride
        self.H = hessian
        self.sv = search_vector
        self.forward = forward
        self.maxstep = 0.3

        self.S = None
        self._s_prev = None
        self._g_prev = None
        self.is_converged = False

        # mass weighing
        if mw:
            self.M = np.sqrt(atoms.get_masses()).reshape(-1, 1)
        else:
            self.M = np.ones(len(atoms)).reshape(-1, 1)
        self.Mi = 1 / self.M

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        self.trajectory = Trajectory(trajectory, 'w')
예제 #31
0
    def __init__(self,
                 atoms,
                 ml_calc,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 master=None,
                 force_consistent=None,
                 optimizer=None,
                 maxstep=0.2,
                 check_downhill=True,
                 ml_fmax=0.5,
                 ml_max_steps=250,
                 callback_before_fit=None,
                 callback_after_ml_opt=None):
        """
        ml_fmax: scaling factor by which the force threshold is reduced in the
                 machine learning runs.
        """
        self.ml_calc = ml_calc
        if optimizer is None:

            def optimizer(atoms, logfile=None):
                return TrustRadiusFIRE(atoms,
                                       trustradius=maxstep,
                                       logfile=logfile)

        self.optimizer = optimizer
        self.check_downhill = check_downhill
        self.previous_energy = None
        self.ml_max_steps = ml_max_steps
        self.callback_before_fit = callback_before_fit
        self.callback_after_ml_opt = callback_after_ml_opt
        self.ml_fmax = ml_fmax
        self.maxstep = maxstep
        Optimizer.__init__(self,
                           atoms,
                           restart,
                           logfile,
                           trajectory,
                           master,
                           force_consistent=force_consistent)
예제 #32
0
    def __init__(self, atoms, logfile='-', trajectory=None,
                 callback_always=False, alpha=70.0):
        """Initialize object

        Parameters:

        callback_always: book
            Should the callback be run after each force call (also in the
            linesearch)

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.

        """
        restart = None
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
        self.force_calls = 0
        self.callback_always = callback_always
        self.H0 = alpha
예제 #33
0
    def __init__(self, atoms, restart=None, logfile='-', maxstep=.2,
                 trajectory=None, c1=.23, c2=0.46, alpha=10., stpmax=50.,
                 use_free_energy=True):
        """Minimize a function using the BFGS algorithm.

        Notes:

            Optimize the function, f, whose gradient is given by fprime
            using the quasi-Newton method of Broyden, Fletcher, Goldfarb,
            and Shanno (BFGS) See Wright, and Nocedal 'Numerical
            Optimization', 1999, pg. 198.

        *See Also*:

          scikits.openopt : SciKit which offers a unified syntax to call
                            this and other solvers.

        """
        self.maxstep = maxstep
        self.stpmax = stpmax
        self.alpha = alpha
        self.H = None
        self.c1 = c1
        self.c2 = c2
        self.force_calls = 0
        self.function_calls = 0
        self.r0 = None
        self.g0 = None
        self.e0 = None
        self.load_restart = False
        self.task = 'START'
        self.rep_count = 0
        self.p = None
        self.alpha_k = None
        self.no_update = False
        self.replay = False
        self.use_free_energy = use_free_energy

        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
    def __init__(self, atoms, logfile='-', trajectory=None):
        Optimizer.__init__(self, atoms, None, logfile, trajectory)

        self.control = atoms.get_control()

        # Make a header for the log
        if self.logfile is not None:
            l = ''
            if isinstance(self.control, DimerControl):
                l = 'MinModeTranslate: STEP      TIME          ENERGY    ' + \
                    'MAX-FORCE     STEPSIZE    CURVATURE  ROT-STEPS\n'
            self.logfile.write(l)
            self.logfile.flush()

        # Load the relevant parameters from control
        self.cg_on = self.control.get_parameter('cg_translation')
        self.trial_step = self.control.get_parameter('trial_trans_step')
        self.max_step = self.control.get_parameter('maximum_translation')

        # Start conjugate gradient
        if self.cg_on:
            self.cg_init = True
예제 #35
0
    def __init__(self, atoms, logfile='-', trajectory=None):
        Optimizer.__init__(self, atoms, None, logfile, trajectory)

        self.control = atoms.get_control()

        # Make a header for the log
        if self.logfile is not None:
            l = ''
            if isinstance(self.control, DimerControl):
                l = 'MinModeTranslate: STEP      TIME          ENERGY    ' + \
                    'MAX-FORCE     STEPSIZE    CURVATURE  ROT-STEPS\n'
            self.logfile.write(l)
            self.logfile.flush()

        # Load the relevant parameters from control
        self.cg_on = self.control.get_parameter('cg_translation')
        self.trial_step = self.control.get_parameter('trial_trans_step')
        self.max_step = self.control.get_parameter('maximum_translation')

        # Start conjugate gradient
        if self.cg_on:
            self.cg_init = True
예제 #36
0
    def __init__(self, atoms, restart=None, logfile='-', maxstep=.2,
                 trajectory=None, c1=0.23, c2=0.46, alpha=10.0, stpmax=50.0):
        """Optimize atomic positions in the BFGSLineSearch algorithm, which
        uses both forces and potential energy information.

        Parameters:

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.
        trajectory: string
            Pickle file used to store trajectory of atomic movement.
        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).
        logfile: string
            Text file used to write summary information.
        """
        self.maxstep = maxstep
        self.stpmax = stpmax
        self.alpha = alpha
        self.H = None
        self.c1 = c1
        self.c2 = c2
        self.force_calls = 0
        self.function_calls = 0
        self.r0 = None
        self.g0 = None
        self.e0 = None
        self.load_restart = False
        self.task = 'START'
        self.rep_count = 0
        self.p = None
        self.alpha_k = None
        self.no_update = False
        self.replay = False

        Optimizer.__init__(self, atoms, restart, logfile, trajectory)
예제 #37
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 fmax=None, converged=None,
                hessianupdate='BFGS',hessian=None,forcemin=True,
                verbosity=None,maxradius=None,
                diagonal=20.,radius=None,
                transitionstate = False):
            
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        self.eps = 1e-12
        self.hessianupdate = hessianupdate
        self.forcemin = forcemin
        self.verbosity = verbosity
        self.diagonal = diagonal

        self.atoms = atoms

        n = len(self.atoms) * 3
        if radius is None: 
                self.radius = 0.05*np.sqrt(n)/10.0
        else:
                self.radius = radius

        if maxradius is None: 
                self.maxradius = 0.5*np.sqrt(n)
        else:
                self.maxradius = maxradius
                
        # 0.01 < radius < maxradius
        self.radius = max(min( self.radius, self.maxradius ), 0.0001)

        self.transitionstate = transitionstate

        # check if this is a nudged elastic band calculation
        if hasattr(atoms,'springconstant'): 
                self.forcemin=False

        self.t0 = time.time() 
예제 #38
0
파일: __init__.py 프로젝트: s-dale/pyIID
 def __init__(self, atoms, restart=None, logfile=None, trajectory=None,
              seed=None,
              verbose=False):
     Optimizer.__init__(self, atoms, restart, logfile, trajectory=None)
     atoms.get_forces()
     atoms.get_potential_energy()
     if seed is None:
         seed = np.random.randint(0, 2 ** 31)
     self.verbose = verbose
     self.random_state = RandomState(seed)
     self.starting_atoms = dc(atoms)
     self.pe = []
     self.metadata = {'seed': seed}
     self.traj = [dc(atoms)]
     print(self.traj[0].get_momenta())
     if trajectory is not None:
         self.trajectory = Trajectory(trajectory, mode='w')
         self.trajectory.write(self.traj[-1])
         if self.verbose:
             print('Trajectory written', len(self.traj))
     else:
         self.trajectory = None
     if verbose:
         print('trajectory file', self.trajectory)
예제 #39
0
파일: bfgs.py 프로젝트: PHOTOX/fuase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 maxstep=None):
        """BFGS optimizer.

        Parameters:

        restart: string
            Pickle file used to store hessian matrix. If set, file with 
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.
        trajectory: string
            Pickle file used to store trajectory of atomic movement.
        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.04 Å).
        """
        
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        if maxstep is not None:
            if maxstep > 1.0:
                raise ValueError('You are using a much too large value for ' +
                                 'the maximum step size: %.1f Å' % maxstep)
            self.maxstep = maxstep
예제 #40
0
파일: fire.py 프로젝트: uu1477/MyAse
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 dt=0.1, maxmove=0.2, dtmax=1.0, Nmin=5, finc=1.1, fdec=0.5,
                 astart=0.1, fa=0.99, a=0.1, master=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        self.dt = dt
        self.Nsteps = 0
        self.maxmove = maxmove
        self.dtmax = dtmax
        self.Nmin = Nmin
        self.finc = finc
        self.fdec = fdec
        self.astart = astart
        self.fa = fa
        self.a = a
예제 #41
0
 def log(self, forces=None):
     if forces is None:
         forces = self.atoms.get_forces()
     return Optimizer.log(self, self._project_forces(forces))
예제 #42
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 prior=None,
                 master=None,
                 noise=0.005,
                 weight=1.,
                 update_prior_strategy='maximum',
                 scale=0.4,
                 force_consistent=None,
                 batch_size=5,
                 update_hyperparams=False):
        """Optimize atomic positions using GPMin algorithm, which uses
        both potential energies and forces information to build a PES
        via Gaussian Process (GP) regression and then minimizes it.

        Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store the training set. If set, file with
            such a name will be searched and the data in the file incorporated
            to the new training set, if the file exists.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        master: boolean
            Defaults to None, which causes only rank 0 to save files. If
            set to True, this rank will save files.

        force_consistent: boolean or None
            Use force-consistent energy calls (as opposed to the energy
            extrapolated to 0 K). By default (force_consistent=None) uses
            force-consistent energies if available in the calculator, but
            falls back to force_consistent=False if not.

        prior: Prior object or None
            Prior for the GP regression of the PES surface
            See ase.optimize.gpmin.prior
            If *Prior* is None, then it is set as the
            ConstantPrior with the constant being updated
            using the update_prior_strategy specified as a parameter

        noise: float
            Regularization parameter for the Gaussian Process Regression.

        weight: float
            Prefactor of the Squared Exponential kernel.
            If *update_hyperparams* is False, changing this parameter
            has no effect on the dynamics of the algorithm.

        update_prior_strategy: string
            Strategy to update the constant from the ConstantPrior
            when more data is collected. It does only work when
            Prior = None

            options:
                'maximum': update the prior to the maximum sampled energy
                'init' : fix the prior to the initial energy
                'average': use the average of sampled energies as prior

        scale: float
            scale of the Squared Exponential Kernel

        update_hyperparams: boolean
            Update the scale of the Squared exponential kernel
            every batch_size-th iteration by maximizing the
            marginal likelhood.

        batch_size: int
            Number of new points in the sample before updating
            the hyperparameters.
            Only relevant if the optimizer is executed in update
            mode: (update = True)
        """

        self.nbatch = batch_size
        self.strategy = update_prior_strategy
        self.update_hp = update_hyperparams
        self.function_calls = 1
        self.force_calls = 0
        self.x_list = []  # Training set features
        self.y_list = []  # Training set targets

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master,
                           force_consistent)

        if prior is None:
            self.update_prior = True
            prior = ConstantPrior(constant=None)

        else:
            self.update_prior = False

        Kernel = SquaredExponential()
        GaussianProcess.__init__(self, prior, Kernel)

        self.set_hyperparams(np.array([weight, scale, noise]))
예제 #43
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 fmax=None, converged=None,
                hessianupdate='BFGS', hessian=None, forcemin=True,
                verbosity=None, maxradius=None,
                diagonal=20., radius=None,
                transitionstate=False, master=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).

        
        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """
 
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        self.eps = 1e-12
        self.hessianupdate = hessianupdate
        self.forcemin = forcemin
        self.verbosity = verbosity
        self.diagonal = diagonal

        self.atoms = atoms

        n = len(self.atoms) * 3
        if radius is None:
                self.radius = 0.05*np.sqrt(n)/10.0
        else:
                self.radius = radius

        if maxradius is None:
                self.maxradius = 0.5*np.sqrt(n)
        else:
                self.maxradius = maxradius
                
        # 0.01 < radius < maxradius
        self.radius = max(min( self.radius, self.maxradius ), 0.0001)

        self.transitionstate = transitionstate

        # check if this is a nudged elastic band calculation
        if hasattr(atoms,'springconstant'):
                self.forcemin=False

        self.t0 = time.time()
예제 #44
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 fmax=None,
                 converged=None,
                 hessianupdate='BFGS',
                 hessian=None,
                 forcemin=True,
                 verbosity=None,
                 maxradius=None,
                 diagonal=20.,
                 radius=None,
                 transitionstate=False,
                 master=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            Used to set the maximum distance an atom can move per
            iteration (default value is 0.2 Angstroms).


        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.
        """

        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        self.eps = 1e-12
        self.hessianupdate = hessianupdate
        self.forcemin = forcemin
        self.verbosity = verbosity
        self.diagonal = diagonal

        self.atoms = atoms

        n = len(self.atoms) * 3
        if radius is None:
            self.radius = 0.05 * np.sqrt(n) / 10.0
        else:
            self.radius = radius

        if maxradius is None:
            self.maxradius = 0.5 * np.sqrt(n)
        else:
            self.maxradius = maxradius

        # 0.01 < radius < maxradius
        self.radius = max(min(self.radius, self.maxradius), 0.0001)

        self.transitionstate = transitionstate

        # check if this is a nudged elastic band calculation
        if hasattr(atoms, 'springconstant'):
            self.forcemin = False

        self.t0 = time.time()
예제 #45
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 maxstep=None, memory=100, damping=1.0, alpha=70.0,
                 use_line_search=False, master=None,
                 force_consistent=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store vectors for updating the inverse of
            Hessian matrix. If set, file with such a name will be searched
            and information stored will be used, if the file exists.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            How far is a single atom allowed to move. This is useful for DFT
            calculations where wavefunctions can be reused if steps are small.
            Default is 0.04 Angstrom.

        memory: int
            Number of steps to be stored. Default value is 100. Three numpy
            arrays of this length containing floats are stored.

        damping: float
            The calculated step is multiplied with this number before added to
            the positions.

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        force_consistent: boolean or None
            Use force-consistent energy calls (as opposed to the energy
            extrapolated to 0 K).  By default (force_consistent=None) uses
            force-consistent energies if available in the calculator, but
            falls back to force_consistent=False if not.
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master,
                           force_consistent=force_consistent)

        if maxstep is not None:
            if maxstep > 1.0:
                raise ValueError('You are using a much too large value for ' +
                                 'the maximum step size: %.1f Angstrom' %
                                 maxstep)
            self.maxstep = maxstep
        else:
            self.maxstep = 0.04

        self.memory = memory
        # Initial approximation of inverse Hessian 1./70. is to emulate the
        # behaviour of BFGS. Note that this is never changed!
        self.H0 = 1. / alpha
        self.damping = damping
        self.use_line_search = use_line_search
        self.p = None
        self.function_calls = 0
        self.force_calls = 0
예제 #46
0
파일: lbfgs.py 프로젝트: rosswhitfield/ase
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 maxstep=None, memory=100, damping=1.0, alpha=70.0,
                 master=None, precon='Exp',
                 use_armijo=True, c1=0.23, c2=0.46, variable_cell=False,
                 rigid_units=None, rotation_factors=None, Hinv=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store vectors for updating the inverse of
            Hessian matrix. If set, file with such a name will be searched
            and information stored will be used, if the file exists.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        maxstep: float
            How far is a single atom allowed to move. This is useful for DFT
            calculations where wavefunctions can be reused if steps are small.
            Default is 0.04 Angstrom.

        memory: int
            Number of steps to be stored. Default value is 100. Three numpy
            arrays of this length containing floats are stored.

        damping: float
            The calculated step is multiplied with this number before added to
            the positions.

        alpha: float
            Initial guess for the Hessian (curvature of energy surface). A
            conservative value of 70.0 is the default, but number of needed
            steps to converge might be less if a lower value is used. However,
            a lower value also means risk of instability.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        precon: ase.optimize.precon.Precon instance or compatible
            Apply the given preconditione during optimization. Defaults to
            'Exp', which constructs an ase.optimize.precon.Exp instance.
            Other options include 'C1' and 'Pfrommer'-
            see the corresponding classes in this module for more details.
            Pass precon=None or precon='ID' to disable preconditioner.

        use_armijo: boolean
            Enforce only the Armijo condition of sufficient decrease of
            of the energy, and not the second Wolff condition for the forces.
            Often significantly faster than full Wolff linesearch.
            Defaults to True.

        c1: float
            c1 parameter for the line search. Default is c1=0.23.

        c2: float
            c2 parameter for the line search. Default is c2=0.46.

        variable_cell: bool
            If True, wrap atoms an ase.constraints.UnitCellFilter to
            relax both postions and cell. Default is False.

        rigid_units: each I = rigid_units[i] is a list of indices, which
            describes a subsystem of atoms that forms a (near-)rigid unit
            If rigid_units is not None, then special search-paths are
            are created to take the rigidness into account

        rotation_factors: list of scalars; acceleration factors deteriming
           the rate of rotation as opposed to the rate of stretch in the
           rigid units
        """
        if variable_cell:
            atoms = UnitCellFilter(atoms)
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        if maxstep is not None:
            if maxstep > 1.0:
                raise ValueError('You are using a much too large value for ' +
                                 'the maximum step size: %.1f Angstrom' %
                                 maxstep)
            self.maxstep = maxstep
        else:
            self.maxstep = 0.04

        self.memory = memory
        self.H0 = 1. / alpha  # Initial approximation of inverse Hessian
        # 1./70. is to emulate the behaviour of BFGS
        # Note that this is never changed!
        self.Hinv = Hinv
        self.damping = damping
        self.p = None

        # construct preconditioner if passed as a string
        if isinstance(precon, basestring):
            if precon == 'C1':
                precon = C1()
            if precon == 'Exp':
                precon = Exp()
            elif precon == 'Pfrommer':
                precon = Pfrommer()
            elif precon == 'ID':
                precon = None
            else:
                raise ValueError('Unknown preconditioner "{0}"'.format(precon))
        self.precon = precon
        self.use_armijo = use_armijo
        self.c1 = c1
        self.c2 = c2

        # CO
        self.rigid_units = rigid_units
        self.rotation_factors = rotation_factors
예제 #47
0
파일: bfgs.py 프로젝트: rosswhitfield/ase
 def todict(self):
     d = Optimizer.todict(self)
     if hasattr(self, 'maxstep'):
         d.update(maxstep=self.maxstep)
     return d
예제 #48
0
 def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
              maxstep=None, cmdline ="optimizer.exe"  ):
     """An interface to geometry optimizer of ParaGauss.
     """
     self.cmdline = cmdline
     Optimizer.__init__(self, atoms, restart, logfile, trajectory)
예제 #49
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 dt=0.1,
                 maxstep=None,
                 maxmove=None,
                 dtmax=1.0,
                 Nmin=5,
                 finc=1.1,
                 fdec=0.5,
                 astart=0.1,
                 fa=0.99,
                 a=0.1,
                 master=None,
                 downhill_check=False,
                 position_reset_callback=None,
                 force_consistent=None):
        """Parameters:

        atoms: Atoms object
            The Atoms object to relax.

        restart: string
            Pickle file used to store hessian matrix. If set, file with
            such a name will be searched and hessian matrix stored will
            be used, if the file exists.

        trajectory: string
            Pickle file used to store trajectory of atomic movement.

        logfile: file object or str
            If *logfile* is a string, a file with that name will be opened.
            Use '-' for stdout.

        master: boolean
            Defaults to None, which causes only rank 0 to save files.  If
            set to true,  this rank will save files.

        downhill_check: boolean
            Downhill check directly compares potential energies of subsequent
            steps of the FIRE algorithm rather than relying on the current
            product v*f that is positive if the FIRE dynamics moves downhill.
            This can detect numerical issues where at large time steps the step
            is uphill in energy even though locally v*f is positive, i.e. the
            algorithm jumps over a valley because of a too large time step.

        position_reset_callback: function(atoms, r, e, e_last)
            Function that takes current *atoms* object, an array of position
            *r* that the optimizer will revert to, current energy *e* and
            energy of last step *e_last*. This is only called if e > e_last.

        force_consistent: boolean or None
            Use force-consistent energy calls (as opposed to the energy
            extrapolated to 0 K).  By default (force_consistent=None) uses
            force-consistent energies if available in the calculator, but
            falls back to force_consistent=False if not.  Only meaningful
            when downhill_check is True.
        """
        Optimizer.__init__(self,
                           atoms,
                           restart,
                           logfile,
                           trajectory,
                           master,
                           force_consistent=force_consistent)

        self.dt = dt

        self.Nsteps = 0

        if maxstep is not None:
            self.maxstep = maxstep
        elif maxmove is not None:
            self.maxstep = maxmove
            warnings.warn('maxmove is deprecated; please use maxstep',
                          np.VisibleDeprecationWarning)
        else:
            self.maxstep = self.defaults['maxstep']

        self.dtmax = dtmax
        self.Nmin = Nmin
        self.finc = finc
        self.fdec = fdec
        self.astart = astart
        self.fa = fa
        self.a = a
        self.downhill_check = downhill_check
        self.position_reset_callback = position_reset_callback
예제 #50
0
파일: lbfgs.py 프로젝트: rosswhitfield/ase
 def run(self, fmax=0.05, steps=100000000, smax=None):
     if smax is None:
         smax = fmax
     self.smax = smax
     return Optimizer.run(self, fmax, steps)
예제 #51
0
파일: IRC.py 프로젝트: zhoutf/ASE_ANI
 def todoct(self):
     d = Optimizer.todict()
     for attr in self._dump_attr:
         if hasattr(self, attr):
             d.update(attr, getattr(self, attr))
     return d
예제 #52
0
    def __init__(self,
                 atoms,
                 restart=None,
                 logfile='-',
                 trajectory=None,
                 maxstep=0.2,
                 master=None,
                 scanned_constraint=None,
                 constraintlist=None,
                 a=None,
                 auto_threshold=True,
                 fixed_conv_ratio=0.8,
                 max_interval_steps=3,
                 interval_step=0.5,
                 log_prefix='',
                 traj_prefix='',
                 adaptive_threshold=0.6,
                 linear_interpol=False,
                 do_cubic=None):
        """ TS Optimization with constraints
            Class for performing 1D-scan maximization along one constraint, while minimizing all
            remaining degrees of freedom.
            The scanned constraint (XX) can be passed in two ways:
            1) (Recommended) scanned_constraint=XX
            2) Has to be the FIRST constraint in the full list of constraints:
               constraintlist = [ XX, other constraints]
            Addditional constraints, such as FixAtoms, will be kept fixed
            Tested only for 
              - scanned_constraint = stretchcombo
              - additional constraints = FixAtoms
            Should work with other additional constraints. 
            To scan other constraints, probably these constraints will require additional
            functions that were specifically added to stretchcombo.
        """
        Optimizer.__init__(self, atoms, restart, logfile, trajectory, master)

        print '********************************************************************************'
        print '*                                    ARPESS                                    *'
        print '*               Automated Relaxed Potential Energy Surface Scans               *'
        print '*  Plessow, P.N. J. Chem. Theory Comput. 2018, 14, 981−990.                    *'
        print '********************************************************************************'
        if maxstep is not None:
            if maxstep > 1.0:
                raise ValueError('You are using a much too large value for ' +
                                 'the maximum step size: %.1f Å' % maxstep)
            self.maxstep = maxstep
        if constraintlist != None:
            self.constraintlist = constraintlist
            self.only_other_constraints = [
                self.constraintlist[-ii]
                for ii in range(1, len(self.constraintlist))
            ]
            self.scanned_constraint = self.constraintlist[0]
        else:
            self.scanned_constraint = scanned_constraint
            self.constraintlist = atoms.constraints
            self.only_other_constraints = [
                const for const in self.constraintlist
                if const != self.scanned_constraint
            ]
        print 'scan along constraint', self.scanned_constraint
        print 'keep constraints', self.only_other_constraints
        self.a = self.scanned_constraint.a
        self.na_step = 0
        self.atoms = atoms
        self.maxstep = maxstep
        self.maxpos_last = 1e-9
        self.max_interval_steps = max_interval_steps
        self.interval_step = interval_step
        self.adaptive_threshold = adaptive_threshold
        self.linear_interpol = linear_interpol
        self.auto_threshold = auto_threshold
        self.fixed_conv_ratio = fixed_conv_ratio
        self.log_prefix = log_prefix
        self.traj_prefix = traj_prefix
        if linear_interpol not in [None, False, True]:
            try:
                self.max_linear_interpol = float(linear_interpol)
                self.linear_interpol = True
            except:
                print 'not sure what to do with linear_interpol=', linear_interpol
                sys.exit(1)
        else:
            self.max_linear_interpol = maxstep
        self.do_cubic = do_cubic
        if do_cubic not in [None, False, True]:
            try:
                self.do_cubic = max(do_cubic, 1.0 / do_cubic)
            except:
                print 'not sure what to do with do_cubic=', do_cubic
                sys.exit(1)
        print 'do_cubic parameter is', do_cubic
예제 #53
0
    def __init__(self, atoms, restart=None, logfile='-', trajectory=None,
                 dt=None):
        Optimizer.__init__(self, atoms, restart, logfile, trajectory)

        if dt is not None:
            self.dt = dt