Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Malthe Kjær Bisbo
GOFEE
Commits
531b2f5e
Commit
531b2f5e
authored
Jan 23, 2020
by
Malthe Kjær Bisbo
Browse files
added partly finished OperationConstraint
parent
d83d12b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
candidate_operations/candidate_generation.py
View file @
531b2f5e
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment