Last active
August 29, 2015 14:11
-
-
Save tschaume/0c6c9c1c56c012147fa5 to your computer and use it in GitHub Desktop.
small pymatgen StructureMatcher test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import isfile | |
from pymatgen import Structure | |
from pymatgen.analysis.structure_matcher import StructureMatcher, ElementComparator | |
from pymatgen.io.cifio import CifWriter, CifParser | |
from mpworks.snl_utils.snl_mongo import SNLMongoAdapter | |
sma = SNLMongoAdapter.auto_load() | |
def get_structure(gid): | |
ciffile = 'snlgroup_id_%d.cif' % gid | |
if not isfile(ciffile): | |
s = Structure.from_dict(sma.snlgroups.find_one({"snlgroup_id": gid})['canonical_snl']) | |
w = CifWriter(s) | |
w.write_file(ciffile) | |
else: | |
s = CifParser(ciffile).get_structures()[0] | |
return s | |
# two sets of snlgroup_id pairs: a couple of canonical structures from the | |
# A. ~405 that didn't match a long time ago but now should match | |
# B. ~3500 that seemed like they matched a few months ago, but we realize now it was due to a bug | |
# duplicate check needs to return True for A. and False for B.! | |
setA = [ | |
[124070, 124069], [88026, 88025], [33468, 33466], | |
[150493, 150494], [31564, 31563], [87801, 87800] | |
] | |
setB = [ | |
[5335, 5336], [123806, 123805], [90125, 90124], | |
[18884, 18883], [129197, 129196], [164662, 164639], | |
] | |
sm = StructureMatcher( | |
ltol=0.2, stol=0.3, angle_tol=5, primitive_cell=True, scale=True, | |
attempt_supercell=False, comparator=ElementComparator() | |
) | |
for list_of_gid_pairs in [setA, setB]: | |
print list_of_gid_pairs | |
for gid_pair in list_of_gid_pairs: | |
s1, s2 = [get_structure(gid) for gid in gid_pair] | |
print gid_pair, sm.fit(s1, s2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment