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 1 commit
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
38 changes: 38 additions & 0 deletions scripts/refcodes_with_properties/entry_property_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ 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?
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 @@ -413,6 +427,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 0


register(ChiralityFilter)


class FilterEvaluation(object):
def __init__(self):
self._methods = []
Expand Down
4 changes: 2 additions & 2 deletions scripts/refcodes_with_properties/refcodes_with_properties.py
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 All @@ -73,4 +73,4 @@
else:
for entry in reader:
if filterer.evaluate(entry):
outfile.write(entry.identifier + "\n")
outfile.write(entry.identifier + "\n")