Commit 1e343e82 authored by Malthe Kjær Bisbo's avatar Malthe Kjær Bisbo
Browse files

works when tested on C6H6

parent ccc788d2
...@@ -66,6 +66,10 @@ class GOFEE(): ...@@ -66,6 +66,10 @@ class GOFEE():
kappa: kappa:
N_relax_final_pop: int or None.
If not None the best 'N_relax_final_pop' structures in the
population is relaxed after the specified number of search
iterations is reached.
""" """
def __init__(self, structures=None, def __init__(self, structures=None,
calc=None, calc=None,
...@@ -74,14 +78,15 @@ class GOFEE(): ...@@ -74,14 +78,15 @@ class GOFEE():
candidate_generator=None, candidate_generator=None,
trajectory=None, trajectory=None,
kappa=2, kappa=2,
Niter=200, max_steps=200,
Ninit=10, Ninit=10,
dmax_cov=3.5, dmax_cov=3.5,
Ncandidates=30, Ncandidates=30,
population_size=5, population_size=5,
dualpoint=True, dualpoint=True,
min_certainty=0.7, min_certainty=0.7,
restart=None): restart=None,
N_relax_final_pop=None):
if structures is None: if structures is None:
assert startgenerator is not None assert startgenerator is not None
...@@ -124,7 +129,7 @@ class GOFEE(): ...@@ -124,7 +129,7 @@ class GOFEE():
indices_fixed = constraint.get_indices() indices_fixed = constraint.get_indices()
self.n_to_optimize -= len(indices_fixed) self.n_to_optimize -= len(indices_fixed)
break break
if candidate_generator is not None: if candidate_generator is not None:
self.candidate_generator = candidate_generator self.candidate_generator = candidate_generator
else: else:
...@@ -141,13 +146,21 @@ class GOFEE(): ...@@ -141,13 +146,21 @@ class GOFEE():
self.master = self.comm.rank == 0 self.master = self.comm.rank == 0
self.kappa = kappa self.kappa = kappa
self.Niter = Niter self.max_steps = max_steps
self.Ninit = Ninit self.Ninit = Ninit
self.dmax_cov = dmax_cov self.dmax_cov = dmax_cov
self.Ncandidates = Ncandidates self.Ncandidates = Ncandidates
self.dualpoint = dualpoint self.dualpoint = dualpoint
self.min_certainty = min_certainty self.min_certainty = min_certainty
self.restart = restart self.restart = restart
if N_relax_final_pop is None:
self.N_relax_final_pop = 0
else:
try:
self.N_relax_final_pop = int(N_relax_final_pop)
except TypeError:
raise
if isinstance(trajectory, str): if isinstance(trajectory, str):
self.trajectory = Trajectory(filename=trajectory, mode='a', master=self.master) self.trajectory = Trajectory(filename=trajectory, mode='a', master=self.master)
...@@ -177,6 +190,7 @@ class GOFEE(): ...@@ -177,6 +190,7 @@ class GOFEE():
generated using self.startgenerator (if supplied), otherwise generated using self.startgenerator (if supplied), otherwise
they are generated by heavily rattling the supplied structures. they are generated by heavily rattling the supplied structures.
""" """
# Collect potentially supplied structures and evaluate # Collect potentially supplied structures and evaluate
# energies and forces if not present. # energies and forces if not present.
structures_init = [] structures_init = []
...@@ -191,9 +205,9 @@ class GOFEE(): ...@@ -191,9 +205,9 @@ class GOFEE():
continue continue
a = self.evaluate(a) a = self.evaluate(a)
structures_init.append(a) structures_init.append(a)
Nremaining = self.Ninit - len(structures_init) Nremaining = self.Ninit - len(structures_init)
if Nremaining > 0 and self.startgenerator is None: if Nremaining > 0 and self.startgenerator is None:
# Initialize rattle-mutation for all atoms. # Initialize rattle-mutation for all atoms.
rattle = RattleMutation(self.n_to_optimize, rattle = RattleMutation(self.n_to_optimize,
...@@ -221,7 +235,7 @@ class GOFEE(): ...@@ -221,7 +235,7 @@ class GOFEE():
def run(self): def run(self):
self.get_initial_structures() self.get_initial_structures()
while self.steps < self.Niter: while self.steps < self.max_steps:
self.print_master('steps:', self.steps) self.print_master('steps:', self.steps)
self.train_surrogate() self.train_surrogate()
self.update_population() self.update_population()
...@@ -259,6 +273,8 @@ class GOFEE(): ...@@ -259,6 +273,8 @@ class GOFEE():
print('anew pred:', anew.info['key_value_pairs']['Epred'], anew.info['key_value_pairs']['Epred_std']) print('anew pred:', anew.info['key_value_pairs']['Epred'], anew.info['key_value_pairs']['Epred_std'])
print('E_true:', [a.get_potential_energy() for a in a_add]) print('E_true:', [a.get_potential_energy() for a in a_add])
print('pop:', [a.get_potential_energy() for a in self.population.pop]) print('pop:', [a.get_potential_energy() for a in self.population.pop])
self.relax_final_population()
def get_dualpoint(self, a, lmax=0.10, Fmax_flat=5): def get_dualpoint(self, a, lmax=0.10, Fmax_flat=5):
"""Returns dual-point structure, i.e. the original structure """Returns dual-point structure, i.e. the original structure
...@@ -401,6 +417,14 @@ class GOFEE(): ...@@ -401,6 +417,14 @@ class GOFEE():
return a return a
def relax_final_population(self):
if self.N_relax_final_pop > 0:
relaxed_population_trajectory = Trajectory(filename='relaxed_final_population.traj',
mode='a', master=self.master)
for a in self.population.pop[:self.N_relax_final_pop]:
a = relax(a, self.calc, Fmax=0.05, steps_max=20)
relaxed_population_trajectory.write(a)
def write(self, a): def write(self, a):
if self.trajectory is not None: if self.trajectory is not None:
self.trajectory.write(a) self.trajectory.write(a)
......
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