Commit 24e0187e authored by Malthe Kjær Bisbo's avatar Malthe Kjær Bisbo
Browse files

changed dmax_cov to max_relax_dist

parent 2e0569ec
...@@ -14,11 +14,11 @@ class BFGSLineSearch_constrained(BFGSLineSearch): ...@@ -14,11 +14,11 @@ class BFGSLineSearch_constrained(BFGSLineSearch):
def __init__(self, atoms, pos_init=None, restart=None, logfile='-', maxstep=.2, def __init__(self, atoms, pos_init=None, restart=None, logfile='-', maxstep=.2,
trajectory=None, c1=0.23, c2=0.46, alpha=10.0, stpmax=50.0, trajectory=None, c1=0.23, c2=0.46, alpha=10.0, stpmax=50.0,
master=None, force_consistent=None, zlim=None, master=None, force_consistent=None, zlim=None,
blmin=None, blmax=None, dmax_cov=3.0, rk=None): blmin=None, blmax=None, max_relax_dist=4.0, rk=None):
""" """
add maximum displacement of single atoms to BFGSLineSearch: add maximum displacement of single atoms to BFGSLineSearch:
dmax_cov: maximum distance the atom is alowed to move from it's initial position. max_relax_dist: maximum distance the atom is alowed to move from it's initial position.
in units of it's covalent distance. in units of it's covalent distance.
""" """
...@@ -28,8 +28,7 @@ class BFGSLineSearch_constrained(BFGSLineSearch): ...@@ -28,8 +28,7 @@ class BFGSLineSearch_constrained(BFGSLineSearch):
self.blmin = blmin self.blmin = blmin
self.blmax = blmax self.blmax = blmax
self.dmax_cov = dmax_cov self.max_relax_dist = max_relax_dist
self.d_cov = 2*np.array([covalent_radii[num] for num in atoms.get_atomic_numbers()])
if pos_init is not None: if pos_init is not None:
self.pos_init = pos_init self.pos_init = pos_init
else: else:
...@@ -71,10 +70,10 @@ class BFGSLineSearch_constrained(BFGSLineSearch): ...@@ -71,10 +70,10 @@ class BFGSLineSearch_constrained(BFGSLineSearch):
def check_displacement(self): def check_displacement(self):
valid_displace = True valid_displace = True
if self.dmax_cov is not None: if self.max_relax_dist is not None:
d = np.array([get_mic_distance(p1,p2,self.cell,self.pbc) for p1,p2 in zip(self.pos_init,self.atoms.get_positions())]) d_relax = np.array([get_mic_distance(p1,p2,self.cell,self.pbc)
max_covDisplace = np.max(d/self.d_cov) for p1,p2 in zip(self.pos_init,self.atoms.get_positions())])
if max_covDisplace > self.dmax_cov: if np.any(d_relax > self.max_relax_dist):
valid_displace = False valid_displace = False
return valid_displace return valid_displace
...@@ -101,7 +100,7 @@ class BFGSLineSearch_constrained(BFGSLineSearch): ...@@ -101,7 +100,7 @@ class BFGSLineSearch_constrained(BFGSLineSearch):
return valid_bondlengths return valid_bondlengths
def relax(structure, calc, Fmax=0.05, steps_max=200, dmax_cov=None): def relax(structure, calc, Fmax=0.05, steps_max=200, max_relax_dist=None):
a = structure.copy() a = structure.copy()
# Set calculator # Set calculator
a.set_calculator(calc) a.set_calculator(calc)
...@@ -112,7 +111,7 @@ def relax(structure, calc, Fmax=0.05, steps_max=200, dmax_cov=None): ...@@ -112,7 +111,7 @@ def relax(structure, calc, Fmax=0.05, steps_max=200, dmax_cov=None):
dyn = BFGSLineSearch_constrained(a, dyn = BFGSLineSearch_constrained(a,
logfile=None, logfile=None,
pos_init=pos_init, pos_init=pos_init,
dmax_cov=dmax_cov) max_relax_dist=max_relax_dist)
dyn.run(fmax = Fmax, steps = steps_max) dyn.run(fmax = Fmax, steps = steps_max)
except Exception as err: except Exception as err:
print('Error in surrogate-relaxation:', err, flush=True) print('Error in surrogate-relaxation:', err, flush=True)
......
...@@ -67,7 +67,7 @@ class GOFEE(): ...@@ -67,7 +67,7 @@ class GOFEE():
startgenerator (if supplied) or by rattling the supplied startgenerator (if supplied) or by rattling the supplied
'structures'. 'structures'.
dmax_cov: float max_relax_dist: float
Max distance that an atom is allowed to move during Max distance that an atom is allowed to move during
surrogate relaxation (in units of covalent distance). surrogate relaxation (in units of covalent distance).
...@@ -98,7 +98,7 @@ class GOFEE(): ...@@ -98,7 +98,7 @@ class GOFEE():
kappa=2, kappa=2,
max_steps=200, max_steps=200,
Ninit=10, Ninit=10,
dmax_cov=3.5, max_relax_dist=3.5,
Ncandidates=30, Ncandidates=30,
population_size=5, population_size=5,
dualpoint=True, dualpoint=True,
...@@ -157,7 +157,7 @@ class GOFEE(): ...@@ -157,7 +157,7 @@ class GOFEE():
self.kappa = kappa self.kappa = kappa
self.max_steps = max_steps self.max_steps = max_steps
self.Ninit = Ninit self.Ninit = Ninit
self.dmax_cov = dmax_cov self.max_relax_dist = max_relax_dist
self.Ncandidates = Ncandidates self.Ncandidates = Ncandidates
self.dualpoint = dualpoint self.dualpoint = dualpoint
self.min_certainty = min_certainty self.min_certainty = min_certainty
...@@ -354,7 +354,7 @@ class GOFEE(): ...@@ -354,7 +354,7 @@ class GOFEE():
surrogate potential. surrogate potential.
""" """
calc = self.gpr.get_calculator(kappa) calc = self.gpr.get_calculator(kappa)
a_relaxed = relax(a, calc, dmax_cov=self.dmax_cov, Fmax=Fmax, steps_max=steps) a_relaxed = relax(a, calc, max_relax_dist=self.max_relax_dist, Fmax=Fmax, steps_max=steps)
# Evaluate uncertainty # Evaluate uncertainty
E, Estd = self.gpr.predict_energy(a_relaxed, eval_std=True) E, Estd = self.gpr.predict_energy(a_relaxed, eval_std=True)
......
...@@ -231,8 +231,7 @@ class GPR(): ...@@ -231,8 +231,7 @@ class GPR():
x0=theta_initial, x0=theta_initial,
bounds=self.kernel.theta_bounds, bounds=self.kernel.theta_bounds,
method='L-BFGS-B', method='L-BFGS-B',
jac=True, jac=True)
options={'gtol': 1e-2, 'ftol': 1e-4})
if not result.success: if not result.success:
warnings.warn(f"L_BFGS_B terminated with state: {result.message}") warnings.warn(f"L_BFGS_B terminated with state: {result.message}")
return result.x, result.fun return result.x, result.fun
...@@ -245,7 +244,6 @@ class GPR(): ...@@ -245,7 +244,6 @@ class GPR():
warnings.warn("fmin_l_bfgs_b terminated abnormally with the " warnings.warn("fmin_l_bfgs_b terminated abnormally with the "
" state: %s" % convergence_dict) " state: %s" % convergence_dict)
return theta_opt, func_min return theta_opt, func_min
def numerical_neg_lml(self, dx=1e-4): def numerical_neg_lml(self, dx=1e-4):
N_data = self.X.shape[0] N_data = self.X.shape[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment