Skip to content

Commit 7d1a968

Browse files
committed
ENH: set site anisotropy per CIF spacegroup
When loading structure from a CIF file, preset site anisotropy according to space group symmetry requirements. After that adhere to the `_atom_site_adp_type` value if present.
1 parent 423fafa commit 7d1a968

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/diffpy/structure/parsers/p_cif.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,8 @@ def _parse_atom_site_aniso_label(self, block):
412412
No return value.
413413
"""
414414
if '_atom_site_aniso_label' not in block: return
415-
# was anisotropy set in the _atom_site_label loop?
416-
atom_site_loop = block.GetLoop('_atom_site_label')
417-
anisotropy_already_set = (
418-
'_atom_site_adp_type' in atom_site_loop or
419-
'_atom_site_thermal_displace_type' in atom_site_loop)
415+
# was anisotropy processed in the _atom_site_label loop?
416+
isotropy_done = _hasAtomSiteADPType(block)
420417
# something to do here:
421418
adp_loop = block.GetLoop('_atom_site_aniso_label')
422419
# index of the _atom_site_label column
@@ -427,7 +424,7 @@ def _parse_atom_site_aniso_label(self, block):
427424
for values in sitedatalist:
428425
idx = self.labelindex[values[ilb]]
429426
a = self.stru[idx]
430-
if not anisotropy_already_set:
427+
if not isotropy_done:
431428
a.anisotropy = True
432429
for fset, val in zip(prop_setters, values):
433430
fset(a, val)
@@ -494,22 +491,32 @@ def _parse_space_group_symop_operation_xyz(self, block):
494491
if self.spacegroup is None:
495492
emsg = "CIF file has unknown space group identifier {!r}."
496493
raise StructureFormatError(emsg.format(sgid))
497-
self._expandAsymmetricUnit()
494+
self._expandAsymmetricUnit(block)
498495
return
499496

500497

501-
def _expandAsymmetricUnit(self):
498+
def _expandAsymmetricUnit(self, block):
502499
"""Perform symmetry expansion of self.stru using self.spacegroup.
500+
503501
This method updates data in stru and eau.
504502
505-
No return value.
503+
Parameters
504+
----------
505+
block : CifBlock
506+
The top-level block containing crystal structure data.
506507
"""
507508
from diffpy.structure.symmetryutilities import ExpandAsymmetricUnit
508-
# get reverse-ordered unique indices
509509
corepos = [a.xyz for a in self.stru]
510510
coreUijs = [a.U for a in self.stru]
511511
self.eau = ExpandAsymmetricUnit(self.spacegroup, corepos, coreUijs,
512512
eps=self.eps)
513+
# setup anisotropy according to symmetry requirements
514+
# was isotropy flag already processed
515+
isotropy_done = (_hasAtomSiteADPType(block) or
516+
'_atom_site_aniso_label' in block)
517+
if not isotropy_done:
518+
for ca, uisotropy in zip(self.stru, self.eau.Uisotropy):
519+
ca.anisotropy = not uisotropy
513520
# build a nested list of new atoms:
514521
newatoms = []
515522
for i, ca in enumerate(self.stru):
@@ -727,3 +734,12 @@ def _suppressCifParserOutput():
727734
finally:
728735
yapps3_compiled_rt.print_error = print_error
729736
pass
737+
738+
739+
def _hasAtomSiteADPType(block):
740+
"""Return True if the CIF specifies _atom_site_adp_type.
741+
"""
742+
atom_site_loop = block.GetLoop('_atom_site_label')
743+
rv = ('_atom_site_adp_type' in atom_site_loop or
744+
'_atom_site_thermal_displace_type' in atom_site_loop)
745+
return rv

src/diffpy/structure/tests/testp_cif.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ def test_spacegroup_isotropy(self):
303303
return
304304

305305

306-
@unittest.expectedFailure
307306
def test_spacegroup_anisotropy(self):
308307
"verify site anisotropy due to site symmetry."
309308
stru = self.ptest.parseFile(self.graphiteciffile)

0 commit comments

Comments
 (0)