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
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
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
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)
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
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
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
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)
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)
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)
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)
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
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)
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)
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
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
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
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
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
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}
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
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()
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)
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, 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)
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
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)
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')
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
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()
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)
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
def __init__(self, atoms, restart=None, logfile='-', trajectory=None, maxstep=None, memory=100, damping=1.0, alpha=70.0, master=None, precon='auto', variable_cell=False, use_armijo=True, c1=0.23, c2=0.46, a_min=None, 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 preconditioner during optimization. Defaults to 'auto', which will choose the `Exp` preconditioner unless the system is too small (< 100 atoms) in which case a standard LBFGS fallback is used. To enforce use of the `Exp` preconditioner, use `precon = 'Exp'`. Other options include 'C1', 'Pfrommer' and 'FF' - see the corresponding classes in the `ase.optimize.precon` module for more details. Pass precon=None or precon='ID' to disable preconditioning. 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. a_min: float minimal value for the line search step parameter. Default is a_min=1e-8 (use_armijo=False) or 1e-10 (use_armijo=True). Higher values can be useful to avoid performing many line searches for comparatively small changes in geometry. 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) # default preconditioner # TODO: introduce a heuristic for different choices of preconditioners if precon == 'auto': if len(atoms) < 100: precon = None warnings.warn( 'The system is likely too small to benefit from ' + 'the standard preconditioner, hence it is ' + 'disabled. To re-enable preconditioning, call' + '`PreconLBFGS` by explicitly providing the ' + 'kwarg `precon`') else: precon = 'Exp' 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 self.a_min = a_min if self.a_min is None: self.a_min = 1e-10 if use_armijo else 1e-8 # CO self.rigid_units = rigid_units self.rotation_factors = rotation_factors
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()
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
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
def __init__(self, atoms, restart=None, logfile='-', trajectory=None, master=None, dihedral=True): """Berny optimizer. This is a light ASE wrapper around the ``Berny`` optimizer from Pyberny_. It is based on a redundant set of internal coordinates, and as such is best suited for optimizing covalently bonded molecules. It does not support periodic boundary conditions. You can find more information on the Pyberny_ website. This optimizer is experimental, and while it can be quite efficient when it works, it can sometimes fail entirely. These issues are most likely related to almost linear bonding angles. For context, see the discussions `here <https://github.com/jhrmnn/pyberny/issues/23>`__ and `here <https://gitlab.com/ase/ase/-/merge_requests/889>`__. .. _Pyberny: https://github.com/jhrmnn/pyberny Parameters: atoms: Atoms object The Atoms object to relax. restart: string Pickle file used to store internal state. If set, file with such a name will be searched and internal state 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. dihedral: boolean Defaults to True, which means that dihedral angles will be used. """ from berny import Berny as _Berny, Geometry self._restart_data = None # Optimizer.__init__() may overwrite Optimizer.__init__(self, atoms, restart, logfile, trajectory, master) geom = Geometry(atoms.get_chemical_symbols(), atoms.positions) self._berny = _Berny( geom, debug=True, restart=self._restart_data, maxsteps=10000000000, # TODO copied from ase.optimize.Optimizer gradientmax=0., gradientrms=0., stepmax=0., steprms=0., dihedral=dihedral, ) # Berny yields the initial geometry the first time because it is # typically used as a generator, see berny.optimize() next(self._berny)
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
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]))
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)
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()
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