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):
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,
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:
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.
"""
......@@ -28,8 +28,7 @@ class BFGSLineSearch_constrained(BFGSLineSearch):
self.blmin = blmin
self.blmax = blmax
self.dmax_cov = dmax_cov
self.d_cov = 2*np.array([covalent_radii[num] for num in atoms.get_atomic_numbers()])
self.max_relax_dist = max_relax_dist
if pos_init is not None:
self.pos_init = pos_init
else:
......@@ -71,10 +70,10 @@ class BFGSLineSearch_constrained(BFGSLineSearch):
def check_displacement(self):
valid_displace = True
if self.dmax_cov 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())])
max_covDisplace = np.max(d/self.d_cov)
if max_covDisplace > self.dmax_cov:
if self.max_relax_dist is not None:
d_relax = np.array([get_mic_distance(p1,p2,self.cell,self.pbc)
for p1,p2 in zip(self.pos_init,self.atoms.get_positions())])
if np.any(d_relax > self.max_relax_dist):
valid_displace = False
return valid_displace
......@@ -101,7 +100,7 @@ class BFGSLineSearch_constrained(BFGSLineSearch):
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()
# Set calculator
a.set_calculator(calc)
......@@ -112,7 +111,7 @@ def relax(structure, calc, Fmax=0.05, steps_max=200, dmax_cov=None):
dyn = BFGSLineSearch_constrained(a,
logfile=None,
pos_init=pos_init,
dmax_cov=dmax_cov)
max_relax_dist=max_relax_dist)
dyn.run(fmax = Fmax, steps = steps_max)
except Exception as err:
print('Error in surrogate-relaxation:', err, flush=True)
......
......@@ -67,7 +67,7 @@ class GOFEE():
startgenerator (if supplied) or by rattling the supplied
'structures'.
dmax_cov: float
max_relax_dist: float
Max distance that an atom is allowed to move during
surrogate relaxation (in units of covalent distance).
......@@ -98,7 +98,7 @@ class GOFEE():
kappa=2,
max_steps=200,
Ninit=10,
dmax_cov=3.5,
max_relax_dist=3.5,
Ncandidates=30,
population_size=5,
dualpoint=True,
......@@ -157,7 +157,7 @@ class GOFEE():
self.kappa = kappa
self.max_steps = max_steps
self.Ninit = Ninit
self.dmax_cov = dmax_cov
self.max_relax_dist = max_relax_dist
self.Ncandidates = Ncandidates
self.dualpoint = dualpoint
self.min_certainty = min_certainty
......@@ -354,7 +354,7 @@ class GOFEE():
surrogate potential.
"""
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
E, Estd = self.gpr.predict_energy(a_relaxed, eval_std=True)
......
......@@ -231,8 +231,7 @@ class GPR():
x0=theta_initial,
bounds=self.kernel.theta_bounds,
method='L-BFGS-B',
jac=True,
options={'gtol': 1e-2, 'ftol': 1e-4})
jac=True)
if not result.success:
warnings.warn(f"L_BFGS_B terminated with state: {result.message}")
return result.x, result.fun
......@@ -246,7 +245,6 @@ class GPR():
" state: %s" % convergence_dict)
return theta_opt, func_min
def numerical_neg_lml(self, dx=1e-4):
N_data = self.X.shape[0]
theta = np.copy(self.kernel.theta)
......
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