Skip to content

Commit eb5e7b7

Browse files
committed
Add ISO import to scriptable
1 parent 98c08c9 commit eb5e7b7

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

GSASII/GSASIIscriptable.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ class variables:
890890
named 'data', as an example, ``G2Project.data['Notebook']['data']``
891891
892892
* The contents of child entries will be found in the item
893-
using the names of the parent and child, for example
893+
using the names of the and child, for example
894894
``G2Project.data['Phases']['NaCl']``
895895
896896
:param str gpxfile: Existing .gpx file to be loaded. If nonexistent,
@@ -1328,7 +1328,8 @@ def add_simulated_powder_histogram(self, histname, iparams, Tmin, Tmax, Tstep=No
13281328
def add_phase(self, phasefile=None, phasename=None, histograms=[],
13291329
fmthint=None, mag=False,
13301330
spacegroup='P 1',cell=None, URL=False,
1331-
useNet = False):
1331+
useNet=False,
1332+
PhaseRef=None):
13321333
"""Loads a phase into the project, usually from a .cif file
13331334
13341335
:param str phasefile: The CIF file (or other file type, see fmthint)
@@ -1364,9 +1365,14 @@ def add_phase(self, phasefile=None, phasename=None, histograms=[],
13641365
most likely to occur with origin-1 settings, where allowed,
13651366
the importer will call Bilbao "CIF to Standard Setting" web service.
13661367
(Default is False).
1368+
:param PhaseRef: Used for magnetic phases only, a reference
1369+
to the (aka chemical/nuclear) phase. This can be the phase
1370+
name (str), the phase's ranId, the phase's index (both int) or
1371+
a phase object (:class:`G2Phase`)
13671372
:returns: A :class:`G2Phase` object representing the
13681373
new phase.
13691374
"""
1375+
parentPhase = None
13701376
LoadG2fil()
13711377
histograms = [self.histogram(h).name for h in histograms]
13721378
if phasefile is None: # create a phase, rather than reading it
@@ -1418,10 +1424,14 @@ def add_phase(self, phasefile=None, phasename=None, histograms=[],
14181424
useNet=useNet)
14191425
phasereader = phasereaders[0]
14201426

1421-
if phasereader.MPhase and mag:
1427+
# for mcifs, the Phase info is in Mphase
1428+
if hasattr(phasereader,'MPhase') and phasereader.MPhase and mag:
14221429
phObj = phasereader.MPhase
14231430
else:
14241431
phObj = phasereader.Phase
1432+
1433+
if phObj['General']['Type'] == 'magnetic' and mag and PhaseRef is not None:
1434+
parentPhase = self.phase(PhaseRef)
14251435

14261436
phasename = phasename or phObj['General']['Name']
14271437
phaseNameList = [p.name for p in self.phases()]
@@ -1446,6 +1456,35 @@ def add_phase(self, phasefile=None, phasename=None, histograms=[],
14461456
else:
14471457
Constraints['Phase'].append(i)
14481458

1459+
# make ISODISTORT magnetic phase constraints here
1460+
if mag and parentPhase:
1461+
oldPhase = parentPhase
1462+
newPhase = phObj
1463+
oRanId = oldPhase['ranId']
1464+
nRanId = newPhase['ranId']
1465+
Vratio = newPhase['General']['Cell'][7]/oldPhase['General']['Cell'][7]
1466+
if 'ISODISTORT' in phObj and 'XformInfo' in phObj['ISODISTORT']:
1467+
import numpy.linalg as nl
1468+
Trans = phObj['ISODISTORT']['XformInfo'].get('Trans',np.eye(3))
1469+
Vec = phObj['ISODISTORT']['XformInfo'].get('offset',[0,0,0])
1470+
Vratio = np.abs(nl.det(Trans)) # better volume ratio
1471+
debug = False
1472+
# create constraints relating two unit cells
1473+
Constraints['Phase'] += G2lat.GenCellConstraints(Trans,oRanId,nRanId,
1474+
G2lat.cell2A(oldPhase['General']['Cell'][1:7]),
1475+
oldPhase['General']['SGData'],
1476+
newPhase['General']['SGData'],debug)
1477+
# create constraints relating the atoms in newPhase to their positions in the chemical cell
1478+
constr,message = G2lat.MatchGenAtomConstraints(
1479+
oldPhase,newPhase,Trans,[0,0,0],Vec)
1480+
if message:
1481+
print('magCIF import Warning:',message)
1482+
Constraints['Phase'] += constr
1483+
for hist in histograms:
1484+
hRanId = self.histogram(hist).ranId
1485+
constrList = G2lat.GenHAPConstraints(Vratio,oRanId,nRanId,hRanId)
1486+
Constraints['HAP'] += constrList
1487+
14491488
data = self.data['Phases'][phasename]
14501489
# generalData = data['General']
14511490
# SGData = generalData['SGData']

0 commit comments

Comments
 (0)