Commit 531b2f5e authored by Malthe Kjær Bisbo's avatar Malthe Kjær Bisbo
Browse files

added partly finished OperationConstraint

parent d83d12b9
...@@ -124,6 +124,48 @@ def random_pos(box): ...@@ -124,6 +124,48 @@ def random_pos(box):
pos += vspan[i] * r[0, i] pos += vspan[i] * r[0, i]
return pos return pos
class OperationConstraint():
""" Class used to enforce constraints on the positions of
atoms in mutation and crossover operations.
box: Box in which atoms are allowed to be placed. It should
have the form [] [p0, vspan] where 'p0' is the position of
the box corner and 'vspan' is a matrix containing the three
spanning vectors.
xlim: On the form [xmin, xmax], specifying, in the x-direction,
the lower and upper limit of the region atoms can be moved
ylim, zlim: See xlim.
def __init__(self, box=None, xlim=None, ylim=None, zlim=None): = box
self.xlim = xlim
self.ylim = ylim
self.zlim = zlim
def check_if_valid(self, positions):
""" Returns whether positions are valid under the
constraints or not.
if is not None:
if self.x is not None:
if (np.any(positions[:,0] < self.xlim[0]) or
np.any(positions[:,0] > self.xlim[1])):
return False
if self.y is not None:
if (np.any(positions[:,1] < self.ylim[0]) or
np.any(positions[:,1] > self.ylim[1])):
return False
if self.z is not None:
if (np.any(positions[:,2] < self.zlim[0]) or
np.any(positions[:,2] > self.zlim[1])):
return False
class StartGenerator(CandidateGenerator): class StartGenerator(CandidateGenerator):
""" Class used to generate random initial candidates. """ Class used to generate random initial candidates.
The candidates are generated by iteratively adding in The candidates are generated by iteratively adding in
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