Skip to content

Commit 744874f

Browse files
committed
Added filter for chirality NO_JIRA
1 parent b05f1db commit 744874f

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

scripts/refcodes_with_properties/entry_property_calculator.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ def __call__(self, theobject):
8585
return value >= self.minimum and value <= self.maximum
8686

8787

88+
class _ValueFilter(_Filter):
89+
def __init__(self, args):
90+
values = [p for p in args.split()]
91+
#To do: add option for two values?
92+
self.expected_value = values[0]
93+
94+
def value(self, theobject):
95+
raise NotImplementedError # override this
96+
97+
def __call__(self, theobject):
98+
value = self.value(theobject)
99+
return value == self.expected_value
100+
101+
88102
class AllowedAtomicNumbersFilter(_Filter):
89103
def __init__(self, args):
90104
self.allowed_atomic_numbers = [int(atomic_number) for atomic_number in args.strip().split()]
@@ -413,6 +427,30 @@ def value(self, entry):
413427
register(SpacegroupNumberFilter)
414428

415429

430+
class ChiralityFilter(_ValueFilter):
431+
def __init__(self, args):
432+
super().__init__(args)
433+
434+
@staticmethod
435+
def name():
436+
return "chirality"
437+
438+
@staticmethod
439+
def helptext():
440+
return "specify the chirality value to be used as filter"
441+
442+
def value(self, entry):
443+
try:
444+
molecule = entry.crystal.molecule
445+
chirality = next((atom.chirality for atom in molecule.atoms if atom.is_chiral), None)
446+
return chirality
447+
except TypeError:
448+
return 0
449+
450+
451+
register(ChiralityFilter)
452+
453+
416454
class FilterEvaluation(object):
417455
def __init__(self):
418456
self._methods = []

scripts/refcodes_with_properties/refcodes_with_properties.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

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

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

@@ -73,4 +73,4 @@
7373
else:
7474
for entry in reader:
7575
if filterer.evaluate(entry):
76-
outfile.write(entry.identifier + "\n")
76+
outfile.write(entry.identifier + "\n")

0 commit comments

Comments
 (0)