Skip to content

Added filter for chirality NO_JIRA #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion scripts/refcodes_with_properties/entry_property_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ def __call__(self, theobject):
return value >= self.minimum and value <= self.maximum


class _ValueFilter(_Filter):
def __init__(self, args):
values = [p for p in args.split()]
#To do: add option for two values?
if values[0] == 'None':
self.expected_value = None
else:
self.expected_value = values[0]

def value(self, theobject):
raise NotImplementedError # override this

def __call__(self, theobject):
value = self.value(theobject)
return value == self.expected_value


class AllowedAtomicNumbersFilter(_Filter):
def __init__(self, args):
self.allowed_atomic_numbers = [int(atomic_number) for atomic_number in args.strip().split()]
Expand Down Expand Up @@ -200,6 +217,25 @@ def value(self, entry):
register(AllHaveSitesFilter)


class Has3DStructure(_ComparativeFilter):
def __init__(self, args):
super().__init__(args)

@staticmethod
def name():
return "has 3D structure"

@staticmethod
def helptext():
return "whether 3D coordinates have been determined for the structure"

def value(self, entry):
return entry.has_3d_structure


register(Has3DStructure)


class DisorderedFilter(_ComparativeFilter):
def __init__(self, args):
super().__init__(args)
Expand Down Expand Up @@ -413,6 +449,30 @@ def value(self, entry):
register(SpacegroupNumberFilter)


class ChiralityFilter(_ValueFilter):
def __init__(self, args):
super().__init__(args)

@staticmethod
def name():
return "chirality"

@staticmethod
def helptext():
return "specify the chirality value to be used as filter"

def value(self, entry):
try:
molecule = entry.crystal.molecule
chirality = next((atom.chirality for atom in molecule.atoms if atom.is_chiral), None)
return chirality
except TypeError:
return None


register(ChiralityFilter)


class FilterEvaluation(object):
def __init__(self):
self._methods = []
Expand All @@ -425,7 +485,7 @@ def evaluate(self, entry):
try:
if not method(entry):
return False
except TypeError:
except (TypeError, RuntimeError):
return False

return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

outfile = sys.stdout
if args.output_file is not None:
outfile = open(args.output_file, 'wb')
outfile = open(args.output_file, 'w', encoding='utf-8')

filterer = entry_property_calculator.parse_control_file(open(control_file, "r").readlines())

Expand Down