Skip to content

Commit

Permalink
threshold for cation-anion distance added as an argument threshold_ca…
Browse files Browse the repository at this point in the history
…tan in def __init__ for ThresholdFitness class
  • Loading branch information
Pau Ferri-Vicedo committed May 29, 2024
1 parent 0cbd24a commit f1c1392
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions VOID/fitness/threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@


THRESHOLD = 1.5
THRESHOLD_CATAN = 2.0
DEFAULT_STRUCTURE = "complex"
STRUCTURE_CHOICES = ["complex", "guest", "host"]
DEFAULT_STEP = False


class ThresholdFitness(Fitness):
def __init__(self, threshold=THRESHOLD, structure="complex", step=False, **kwargs):
def __init__(
self,
threshold=THRESHOLD,
threshold_catan=THRESHOLD_CATAN,
structure="complex",
step=False,
**kwargs,
):
"""Fitness is positive if the minimum distance is above
the given threshold.
Expand All @@ -23,6 +31,7 @@ def __init__(self, threshold=THRESHOLD, structure="complex", step=False, **kwarg
"""
super().__init__()
self.threshold = threshold
self.threshold_catan = threshold_catan
self.step = step

if structure not in STRUCTURE_CHOICES:
Expand All @@ -39,6 +48,12 @@ def add_arguments(parser):
help="threshold for distance calculations (default: %(default)s)",
default=THRESHOLD,
)
parser.add_argument(
"--threshold_catan",
type=float,
help="threshold for cation-anion distance calculations (default: %(default)s)",
default=THRESHOLD_CATAN,
)
parser.add_argument(
"--structure",
type=str,
Expand Down Expand Up @@ -288,14 +303,14 @@ def get_catan_distances(
distances_catan.append(distances_cation_anion)

if (
any(dist < 2.0 for sublist in distances_catan for dist in sublist)
any(
dist < self.threshold_catan
for sublist in distances_catan
for dist in sublist
)
and self.normalize(self.get_distances(complex).min() - self.threshold) > 0
):
print("Optimal distance found! Aborting the run")
print(
"Distances between cation and acid oxygens are:",
distances_catan,
)
print("Optimal cation-anion distance found! Aborting the run")
return True, distances_catan

else:
Expand Down

0 comments on commit f1c1392

Please sign in to comment.