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):
pos += vspan[i] * r[0, i]
return pos
class OperationConstraint():
""" Class used to enforce constraints on the positions of
atoms in mutation and crossover operations.
Parameters:
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
within.
ylim, zlim: See xlim.
"""
def __init__(self, box=None, xlim=None, ylim=None, zlim=None):
self.box = 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 self.box is not None:
pass
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 used to generate random initial candidates.
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