From 5145a0a32ab99ab9981d5c4d9ebbae3e643ebf80 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Thu, 15 Aug 2024 13:08:05 -0700 Subject: [PATCH 01/10] fixing some translation issues in origin choice 2 --- hexrd/material/symmetry.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/hexrd/material/symmetry.py b/hexrd/material/symmetry.py index ed8830fb..5ea30a1b 100644 --- a/hexrd/material/symmetry.py +++ b/hexrd/material/symmetry.py @@ -80,6 +80,7 @@ def GeneratorString(sgnum): def MakeGenerators(genstr, setting): + t = 'aOOO' mat = SYM_fillgen(t) genmat = mat @@ -113,22 +114,29 @@ def MakeGenerators(genstr, setting): if(genstr[istop] != '0'): if(setting != 0): t = genstr[istop+1:istop+4] - trans = np.array([constants.SYM_GENERATORS[t[0]],\ - constants.SYM_GENERATORS[t[1]],\ - constants.SYM_GENERATORS[t[2]] - ]) - for i in range(genmat.shape[0]): - genmat[i,0:3,3] -= trans + t = 'a' + t # get the translation without any rotation + sym = np.squeeze(SYM_fillgen(t, sgn=-1)) + sym2 = np.squeeze(SYM_fillgen(t)) + for i in range(1, genmat.shape[0]): + generator = np.dot(sym2, np.dot( + np.squeeze(genmat[i,:,:]), + sym)) + frac = np.modf(generator[0:3,3])[0] + frac[frac < 0.] += 1. + frac[np.abs(frac) < 1E-5] = 0.0 + frac[np.abs(frac-1.0) < 1E-5] = 0.0 + generator[0:3,3] = frac + genmat[i,:,:] = generator return genmat, centrosymmetric -def SYM_fillgen(t): +def SYM_fillgen(t, sgn=1): mat = np.zeros([4,4]) mat[3,3] = 1. mat[0:3,0:3] = constants.SYM_GENERATORS[t[0]] - mat[0:3,3] = np.array([constants.SYM_GENERATORS[t[1]],\ - constants.SYM_GENERATORS[t[2]],\ + mat[0:3,3] = sgn*np.array([constants.SYM_GENERATORS[t[1]], + constants.SYM_GENERATORS[t[2]], constants.SYM_GENERATORS[t[3]] ]) From 6a975de7fb0e43f8bddf88496bb02cd88acd42ca Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Thu, 15 Aug 2024 13:28:03 -0700 Subject: [PATCH 02/10] add space groups with 2 origin choices and the respective origin site symmetries. --- hexrd/constants.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/hexrd/constants.py b/hexrd/constants.py index aa813e52..42cf1f0b 100644 --- a/hexrd/constants.py +++ b/hexrd/constants.py @@ -1100,6 +1100,38 @@ def is_writable_file(path): SYM_GENERATORS['Y'] = -1./4. SYM_GENERATORS['Z'] = -1./8. +''' this dictionary contains the space group numbers +which have two origin choices the two values are the +site symmetries of the origin. There are 24 such space +groups +''' +two_origin_choice = { +48 : ['222', '-1'], +50 : ['222/n', '-1'], +59 : ['mm2/n', '-1'], +68 : ['222', '-1'], +70 : ['222', '-1'], +85 : ['-4', '-1'], +86 : ['-4', '-1'], +88 : ['-4', '-1'], +125: ['422', '2/m'], +126: ['422/n', '-1'], +129: ['-4m2', '2/m'], +130: ['-4/ncn', '-1'], +133: ['-4121/c', '-1'], +134: ['-42m', '2/m'], +137: ['-4m2/n', '-1'], +138: ['-4cg', '2/m'], +141: ['-4m2', '2/m'], +142: ['-4c21', '-1'], +201: ['23', '-3'], +203: ['23', '-3'], +222: ['432', '-3'], +224: ['-43m', '-3m'], +227: ['-43m', '-3m'], +228: ['23', '-3'], +} + ''' @AUTHOR Saransh Singh, Lawrence Livermore National Lab, saransh1@llnl.gov From 8655bd461199b1f50b8e60948b2c1413b4999f6f Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Thu, 15 Aug 2024 14:24:19 -0700 Subject: [PATCH 03/10] correctly handle passing of sgsetting for file reads --- hexrd/material/material.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hexrd/material/material.py b/hexrd/material/material.py index 30b89e9b..5ca1ca67 100644 --- a/hexrd/material/material.py +++ b/hexrd/material/material.py @@ -37,7 +37,10 @@ from hexrd.material.crystallography import PlaneData as PData from hexrd.material import symmetry, unitcell from hexrd.valunits import valWUnit -from hexrd.constants import ptable, ptableinverse, chargestate +from hexrd.constants import (ptable, + ptableinverse, + chargestate, + two_origin_choice) from os import path from pathlib import Path @@ -76,6 +79,11 @@ def _kev(x): def _key(x): return x.name +def get_default_sgsetting(sgnum): + if sgnum in two_origin_choice: + return 1 + else: + return 0 # # ---------------------------------------------------CLASS: Material @@ -148,7 +156,7 @@ def __init__( material_file=None, dmin=None, kev=None, - sgsetting=DFLT_SGSETTING, + sgsetting=None, ): """Constructor for Material @@ -165,8 +173,6 @@ def __init__( self.description = '' - self.sgsetting = sgsetting - if material_file: # >> @ date 08/20/2020 SS removing dependence on hklmax if isinstance(material_file, (Path, str)): @@ -180,6 +186,9 @@ def __init__( self._readCif(material_file) elif isinstance(material_file, h5py.Group) or form in h5_suffixes: self._readHDFxtal(fhdf=material_file, xtal=name) + if sgsetting is not None: + if sgsetting in [0, 1]: + self._sgsetting = sgsetting else: # default name self._name = Material.DFLT_XTAL @@ -189,8 +198,8 @@ def __init__( # self.description = '' # - self.sgnum = Material.DFLT_SGNUM self._sgsetting = Material.DFLT_SGSETTING + self.sgnum = Material.DFLT_SGNUM # self._atominfo = Material.DFLT_ATOMINFO # @@ -645,6 +654,7 @@ def _readCif(self, fcif=DFLT_NAME + '.cif'): lparms[i] = _degrees(lparms[i]) self._lparms = lparms + self._sgsetting = get_default_sgsetting(sgnum) self.sgnum = sgnum # fractional atomic site, occ and vibration amplitude @@ -795,7 +805,6 @@ def _readCif(self, fcif=DFLT_NAME + '.cif'): self._atomtype = np.asarray(atomtype).astype(np.int32) self._charge = charge - self._sgsetting = 0 self._dmin = Material.DFLT_DMIN self._beamEnergy = Material.DFLT_KEV @@ -864,6 +873,9 @@ def _readHDFxtal(self, fhdf=DFLT_NAME, xtal=DFLT_NAME): self._lparms = lparms # fill space group and lattice parameters + self._sgsetting = np.array( + gid.get('SpaceGroupSetting'), dtype=np.int32 + ).item() self.sgnum = sgnum # the U factors are related to B by the relation B = 8pi^2 U @@ -880,10 +892,6 @@ def _readHDFxtal(self, fhdf=DFLT_NAME, xtal=DFLT_NAME): self._charge = ['0'] * self._atomtype.shape[0] self._atom_ntype = self._atomtype.shape[0] - self._sgsetting = np.array( - gid.get('SpaceGroupSetting'), dtype=np.int32 - ).item() - if 'stiffness' in gid: # we're assuming the stiffness is in units of GPa self.stiffness = np.array(gid.get('stiffness')) @@ -1428,8 +1436,7 @@ def loadMaterialList(cfgFile): def load_materials_hdf5( - f, dmin=None, kev=None, sgsetting=Material.DFLT_SGSETTING -): + f, dmin=None, kev=None): """Load materials from an HDF5 file The file uses the HDF5 file format. @@ -1452,7 +1459,6 @@ def load_materials_hdf5( 'material_file': f, 'dmin': dmin, 'kev': kev, - 'sgsetting': sgsetting, } return {name: Material(name, **kwargs) for name in names} From 5602363152ff9e7ae91c313f26c37f160578a031 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Tue, 20 Aug 2024 11:37:36 -0700 Subject: [PATCH 04/10] PEP8 fixes. Moved two_origin_choice to materials.symbols --- hexrd/constants.py | 90 +++++++++++++------------------ hexrd/material/material.py | 13 ++--- hexrd/material/mksupport.py | 22 ++++---- hexrd/material/symbols.py | 42 +++++++++++---- hexrd/material/symmetry.py | 105 ++++++++++++++++++------------------ 5 files changed, 143 insertions(+), 129 deletions(-) diff --git a/hexrd/constants.py b/hexrd/constants.py index 42cf1f0b..932814ae 100644 --- a/hexrd/constants.py +++ b/hexrd/constants.py @@ -82,7 +82,8 @@ zeros_3x1 = np.zeros((3, 1)) zeros_6x1 = np.zeros((6, 1)) -# reference beam direction and eta=0 ref in LAB FRAME for standard geometry +'''reference beam direction and +eta=0 ref in LAB FRAME for standard geometry''' beam_vec = -lab_z eta_vec = lab_x @@ -162,7 +163,9 @@ 3628800.]).astype(np.complex128) """ ->> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab, saransh1@llnl.gov +>> @AUTHOR: Saransh Singh, + Lawrence Livermore National Lab, + saransh1@llnl.gov >> @DATE: 11/28/2022 SS 1.0 original >> @DETAILS: constants for rodrigues FZ """ @@ -177,7 +180,9 @@ ) ''' ->> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab, saransh1@llnl.gov +>> @AUTHOR: Saransh Singh, + Lawrence Livermore National Lab, + saransh1@llnl.gov >> @DATE: 10/28/2020 SS 1.0 original >> @DETAILS: constants for sphere sectors used for IPF coloring ''' @@ -263,7 +268,8 @@ def set_numba_cache(): 4. The NUMBA_CACHE_DIR environment variable is not defined If all of these are true, then numba will try to write to a - directory where it doesn't have permission, and cause the application to + directory where it doesn't have permission, + and cause the application to freeze. Avoid that by setting the cache dir ourselves. """ @@ -316,8 +322,10 @@ def is_writable_file(path): cRestmass = 9.1093837090E-31 ''' -adding another parametrization of the scattering factors. these are more recent -and more accurate. also used in Vesta (copied from there). see: +adding another parametrization of the +scattering factors. these are more recent +and more accurate. also used in Vesta +(copied from there). see: New Analytical coherent Scattering-Factor Functions for Free Atoms and Ions BY D. WAASMAIER AND A. KIRFEL @@ -638,7 +646,9 @@ def is_writable_file(path): 'Cf': ['0'] } ''' -this dictionary tabulates the small nuclear Thomson term fNT for all elements up to Z=92 +this dictionary tabulates the small +nuclear Thomson term fNT for all +elements up to Z=92 ''' fNT = { 'H':-0.00054423,'He':-0.00054817,'Li':-0.00071131,'Be':-0.00097394,'B':-0.0012687,'C':-0.0016442,'N':-0.0019191,'O':-0.0021944, @@ -737,8 +747,10 @@ def is_writable_file(path): 229 ]) -''' this variable encodes all the generators (including translations) for all 230 space groups - will be used to compute the full space group symmetry operators +''' this variable encodes all the generators +(including translations) for all 230 space groups +will be used to compute the full space group symmetry +operators ''' SYM_GL = [ "000 ", "100 ", "01cOOO0 ", @@ -996,8 +1008,10 @@ def is_writable_file(path): } ''' -this dictionary contains the generators encoded in each letter of the generator string -the full symmetry is generated by the repeated action of the generator matrix +this dictionary contains the generators encoded +in each letter of the generator string +the full symmetry is generated by the repeated +action of the generator matrix ''' ''' rotational, inversions, mirrors etc. components @@ -1100,49 +1114,21 @@ def is_writable_file(path): SYM_GENERATORS['Y'] = -1./4. SYM_GENERATORS['Z'] = -1./8. -''' this dictionary contains the space group numbers -which have two origin choices the two values are the -site symmetries of the origin. There are 24 such space -groups -''' -two_origin_choice = { -48 : ['222', '-1'], -50 : ['222/n', '-1'], -59 : ['mm2/n', '-1'], -68 : ['222', '-1'], -70 : ['222', '-1'], -85 : ['-4', '-1'], -86 : ['-4', '-1'], -88 : ['-4', '-1'], -125: ['422', '2/m'], -126: ['422/n', '-1'], -129: ['-4m2', '2/m'], -130: ['-4/ncn', '-1'], -133: ['-4121/c', '-1'], -134: ['-42m', '2/m'], -137: ['-4m2/n', '-1'], -138: ['-4cg', '2/m'], -141: ['-4m2', '2/m'], -142: ['-4c21', '-1'], -201: ['23', '-3'], -203: ['23', '-3'], -222: ['432', '-3'], -224: ['-43m', '-3m'], -227: ['-43m', '-3m'], -228: ['23', '-3'], -} - - ''' - @AUTHOR Saransh Singh, Lawrence Livermore National Lab, saransh1@llnl.gov + @AUTHOR Saransh Singh, + Lawrence Livermore National Lab, + saransh1@llnl.gov @DATE 11/23/2020 SS 1.0 original - @DETAIL. this list of symbols will help us to genrate the point group symmetries - in the cartesian space for any point group. this is needed for the - supergroup symmetry usd in the coloring scheme used in the package. this - needs to be a separate set of routines because the supergroup can be a - point group which is not the laue group of the crystal (e.g. m-3 --> m-3m) - the notation used will be the same as the one used for the space group - without any translations. + @DETAIL. this list of symbols will help us to genrate + the point group symmetries in the cartesian + space for any point group. this is needed for + the supergroup symmetry usd in the coloring + scheme used in the package. this needs to be a + separate set of routines because the supergroup + can be a point group which is not the laue group + of the crystal (e.g. m-3 --> m-3m) the notation + used will be the same as the one used for the + space group without any translations. ''' SYM_GL_PG = { 'c1': '1a', # only identity rotation diff --git a/hexrd/material/material.py b/hexrd/material/material.py index 5ca1ca67..b447c6fd 100644 --- a/hexrd/material/material.py +++ b/hexrd/material/material.py @@ -36,11 +36,11 @@ from hexrd.material.crystallography import PlaneData as PData from hexrd.material import symmetry, unitcell +from hexrd.material.symbols import two_origin_choice from hexrd.valunits import valWUnit from hexrd.constants import (ptable, - ptableinverse, - chargestate, - two_origin_choice) + ptableinverse, + chargestate) from os import path from pathlib import Path @@ -79,6 +79,7 @@ def _kev(x): def _key(x): return x.name + def get_default_sgsetting(sgnum): if sgnum in two_origin_choice: return 1 @@ -187,8 +188,8 @@ def __init__( elif isinstance(material_file, h5py.Group) or form in h5_suffixes: self._readHDFxtal(fhdf=material_file, xtal=name) if sgsetting is not None: - if sgsetting in [0, 1]: - self._sgsetting = sgsetting + if sgsetting in [0, 1]: + self._sgsetting = sgsetting else: # default name self._name = Material.DFLT_XTAL @@ -1436,7 +1437,7 @@ def loadMaterialList(cfgFile): def load_materials_hdf5( - f, dmin=None, kev=None): + f, dmin=None, kev=None): """Load materials from an HDF5 file The file uses the HDF5 file format. diff --git a/hexrd/material/mksupport.py b/hexrd/material/mksupport.py index 08327262..73f71870 100644 --- a/hexrd/material/mksupport.py +++ b/hexrd/material/mksupport.py @@ -1,6 +1,9 @@ -from hexrd.material.symbols import pstr_Elements, sitesym, \ - tworig, PrintPossibleSG, TRIG, pstr_spacegroup,\ - pstr_mkxtal +from hexrd.material.symbols import (pstr_Elements, + two_origin_choice, + PrintPossibleSG, + TRIG, + pstr_spacegroup, + pstr_mkxtal) import h5py import os import numpy as np @@ -8,6 +11,7 @@ import getpass from hexrd.material.unitcell import _StiffnessDict, _pgDict + def mk(filename, xtalname): # print some initial information for the user @@ -23,7 +27,7 @@ def mk(filename, xtalname): AtomInfo = GetAtomInfo() AtomInfo.update({'file': filename, 'xtalname': xtalname, - 'xtal_sys': xtal_sys, 'SG': space_group,\ + 'xtal_sys': xtal_sys, 'SG': space_group, 'SGsetting': iset}) Write2H5File(AtomInfo, lat_param) @@ -275,14 +279,15 @@ def GetSpaceGroup(xtal_sys, btrigonal, bhexset): def SpaceGroupSetting(sgnum): iset = 1 - if(sgnum in tworig): - idx = tworig.index(sgnum) + if(sgnum in two_origin_choice): + sitesym1 = two_origin_choice[sgnum][0] + sitesym2 = two_origin_choice[sgnum][1] print(' ---------------------------------------------') print(' This space group has two origin settings.') print(' The first setting has site symmetry : ' + - sitesym[2*idx - 2]) + sitesym1) print(' the second setting has site symmetry : ' + - sitesym[2*idx - 1]) + sitesym2) iset = input(' Which setting do you wish to use (1/2) : ') if(not iset.isdigit()): raise ValueError("Invalid integer value for atomic number.") @@ -294,7 +299,6 @@ def SpaceGroupSetting(sgnum): return iset-1 - def GetAtomInfo(): print(pstr_Elements) diff --git a/hexrd/material/symbols.py b/hexrd/material/symbols.py index ccc65ef3..18d8479b 100644 --- a/hexrd/material/symbols.py +++ b/hexrd/material/symbols.py @@ -120,17 +120,37 @@ '89:Ac 90:Th 91:Pa 92:U' + "\n" \ ' ----------------------------------------------------------------------------------------------------------' -sitesym = ['222 ',' -1 ','222/n ',' -1 ','mm2/n ',' -1 ', \ -'222 ',' -1 ','222 ',' -1 ','-4 ',' -1 ', \ -'-4 ',' -1 ','-4 ',' -1 ','422 ','2/m ', \ -'422/n ',' -1 ','-4m2 ','2/m ','-4/ncn ',' -1 ', \ -'-4121/c',' -1 ','-42m ','2/m ','-4m2/n ',' -1 ', \ -'-4cg ','2/m ','-4m2 ','2/m ','-4c21 ',' -1 ', \ -'23 ',' -3 ','23 ',' -3 ','432 ',' -3 ', \ -'-43m ','-3m ','-43m ','-3m ','23 ',' -3 '] - -tworig = [48,50,59,68,70,85,86,88,125,126,129,130,133,134,137,138,\ -141,142,201,203,222,224,227,228] +''' this dictionary contains the space group numbers +which have two origin choices the two values are the +site symmetries of the origin. There are 24 such space +groups +''' +two_origin_choice = { +48 : ['222', '-1'], +50 : ['222/n', '-1'], +59 : ['mm2/n', '-1'], +68 : ['222', '-1'], +70 : ['222', '-1'], +85 : ['-4', '-1'], +86 : ['-4', '-1'], +88 : ['-4', '-1'], +125: ['422', '2/m'], +126: ['422/n', '-1'], +129: ['-4m2', '2/m'], +130: ['-4/ncn', '-1'], +133: ['-4121/c', '-1'], +134: ['-42m', '2/m'], +137: ['-4m2/n', '-1'], +138: ['-4cg', '2/m'], +141: ['-4m2', '2/m'], +142: ['-4c21', '-1'], +201: ['23', '-3'], +203: ['23', '-3'], +222: ['432', '-3'], +224: ['-43m', '-3m'], +227: ['-43m', '-3m'], +228: ['23', '-3'], +} def PrintPossibleSG(xtal_sys): diff --git a/hexrd/material/symmetry.py b/hexrd/material/symmetry.py index 5ea30a1b..0d614f7f 100644 --- a/hexrd/material/symmetry.py +++ b/hexrd/material/symmetry.py @@ -31,9 +31,9 @@ import numpy as np from numba import njit -from numpy import array, sqrt, pi, \ - vstack, c_, dot, \ - argmax +from numpy import (array, sqrt, pi, + vstack, c_, dot, + argmax) # from hexrd.rotations import quatOfAngleAxis, quatProductMatrix, fixQuat from hexrd import rotations as rot @@ -41,8 +41,9 @@ from hexrd.utils.decorators import memoize # Imports in case others are importing from here -from hexrd.rotations import toFundamentalRegion, ltypeOfLaueGroup, \ - quatOfLaueGroup +from hexrd.rotations import (toFundamentalRegion, + ltypeOfLaueGroup, + quatOfLaueGroup) # ============================================================================= @@ -78,8 +79,8 @@ def GeneratorString(sgnum): return constants.SYM_GL[sg] -def MakeGenerators(genstr, setting): +def MakeGenerators(genstr, setting): t = 'aOOO' mat = SYM_fillgen(t) @@ -99,7 +100,7 @@ def MakeGenerators(genstr, setting): if(n > 0): for i in range(n): istart = 2 + i * 4 - istop = 2 + (i+1) * 4 + istop = 2 + (i+1) * 4 t = genstr[istart:istop] @@ -114,39 +115,39 @@ def MakeGenerators(genstr, setting): if(genstr[istop] != '0'): if(setting != 0): t = genstr[istop+1:istop+4] - t = 'a' + t # get the translation without any rotation - sym = np.squeeze(SYM_fillgen(t, sgn=-1)) + t = 'a' + t # get the translation without any rotation + sym = np.squeeze(SYM_fillgen(t, sgn=-1)) sym2 = np.squeeze(SYM_fillgen(t)) for i in range(1, genmat.shape[0]): generator = np.dot(sym2, np.dot( - np.squeeze(genmat[i,:,:]), - sym)) - frac = np.modf(generator[0:3,3])[0] + np.squeeze(genmat[i, :, :]), + sym)) + frac = np.modf(generator[0:3, 3])[0] frac[frac < 0.] += 1. frac[np.abs(frac) < 1E-5] = 0.0 frac[np.abs(frac-1.0) < 1E-5] = 0.0 - generator[0:3,3] = frac - genmat[i,:,:] = generator + generator[0:3, 3] = frac + genmat[i, :, :] = generator return genmat, centrosymmetric + def SYM_fillgen(t, sgn=1): - mat = np.zeros([4,4]) - mat[3,3] = 1. + mat = np.zeros([4, 4]) + mat[3, 3] = 1. - mat[0:3,0:3] = constants.SYM_GENERATORS[t[0]] - mat[0:3,3] = sgn*np.array([constants.SYM_GENERATORS[t[1]], - constants.SYM_GENERATORS[t[2]], - constants.SYM_GENERATORS[t[3]] - ]) + mat[0:3, 0:3] = constants.SYM_GENERATORS[t[0]] + mat[0:3, 3] = sgn*np.array([constants.SYM_GENERATORS[t[1]], + constants.SYM_GENERATORS[t[2]], + constants.SYM_GENERATORS[t[3]] + ]) - mat = np.broadcast_to(mat, [1,4,4]) + mat = np.broadcast_to(mat, [1, 4, 4]) return mat @memoize(maxsize=20) def GenerateSGSym(sgnum, setting=0): - ''' get the generators for a space group using the generator string @@ -173,22 +174,22 @@ def GenerateSGSym(sgnum, setting=0): k1 = 0 while k1 < nsym: - g1 = np.squeeze(SYM_SG[k1,:,:]) + g1 = np.squeeze(SYM_SG[k1, :, :]) k2 = k1 while k2 < nsym: - g2 = np.squeeze(SYM_SG[k2,:,:]) + g2 = np.squeeze(SYM_SG[k2, :, :]) gnew = np.dot(g1, g2) # only fractional parts - frac = np.modf(gnew[0:3,3])[0] + frac = np.modf(gnew[0:3, 3])[0] frac[frac < 0.] += 1. frac[np.abs(frac) < 1E-5] = 0.0 frac[np.abs(frac-1.0) < 1E-5] = 0.0 - gnew[0:3,3] = frac + gnew[0:3, 3] = frac if(isnew(gnew, SYM_SG)): - gnew = np.broadcast_to(gnew, [1,4,4]) + gnew = np.broadcast_to(gnew, [1, 4, 4]) SYM_SG = np.concatenate((SYM_SG, gnew)) nsym += 1 @@ -203,12 +204,12 @@ def GenerateSGSym(sgnum, setting=0): SYM_PG_d_laue = GeneratePGSym_Laue(SYM_PG_d) for s in SYM_PG_d: - if(np.allclose(-np.eye(3),s)): + if(np.allclose(-np.eye(3), s)): centrosymmetric = True - return SYM_SG, SYM_PG_d, SYM_PG_d_laue, centrosymmetric, symmorphic + def GeneratePGSym(SYM_SG): ''' calculate the direct space point group symmetries @@ -222,19 +223,20 @@ def GeneratePGSym(SYM_SG): nsgsym = SYM_SG.shape[0] # first fill the identity rotation - SYM_PG_d = SYM_SG[0,0:3,0:3] - SYM_PG_d = np.broadcast_to(SYM_PG_d,[1,3,3]) - - for i in range(1,nsgsym): - g = SYM_SG[i,:,:] - t = g[0:3,3] - g = g[0:3,0:3] - if(isnew(g,SYM_PG_d)): - g = np.broadcast_to(g,[1,3,3]) + SYM_PG_d = SYM_SG[0, 0:3, 0:3] + SYM_PG_d = np.broadcast_to(SYM_PG_d, [1, 3, 3]) + + for i in range(1, nsgsym): + g = SYM_SG[i, :, :] + t = g[0:3, 3] + g = g[0:3, 0:3] + if(isnew(g, SYM_PG_d)): + g = np.broadcast_to(g, [1, 3, 3]) SYM_PG_d = np.concatenate((SYM_PG_d, g)) return SYM_PG_d.astype(np.int32) + def GeneratePGSym_Laue(SYM_PG_d): ''' generate the laue group symmetry for the given set of @@ -248,7 +250,7 @@ def GeneratePGSym_Laue(SYM_PG_d): first check if the group already has the inversion symmetry ''' for s in SYM_PG_d: - if(np.allclose(s,-np.eye(3))): + if(np.allclose(s, -np.eye(3))): return SYM_PG_d ''' @@ -256,7 +258,7 @@ def GeneratePGSym_Laue(SYM_PG_d): add the inversion symmetry ''' SYM_PG_d_laue = SYM_PG_d - g = np.broadcast_to(-np.eye(3).astype(np.int32),[1,3,3]) + g = np.broadcast_to(-np.eye(3).astype(np.int32), [1, 3, 3]) SYM_PG_d_laue = np.concatenate((SYM_PG_d_laue, g)) ''' @@ -266,14 +268,14 @@ def GeneratePGSym_Laue(SYM_PG_d): nsym = SYM_PG_d_laue.shape[0] k1 = 0 while k1 < nsym: - g1 = np.squeeze(SYM_PG_d_laue[k1,:,:]) + g1 = np.squeeze(SYM_PG_d_laue[k1, :, :]) k2 = k1 while k2 < nsym: - g2 = np.squeeze(SYM_PG_d_laue[k2,:,:]) + g2 = np.squeeze(SYM_PG_d_laue[k2, :, :]) gnew = np.dot(g1, g2) if(isnew(gnew, SYM_PG_d_laue)): - gnew = np.broadcast_to(gnew, [1,3,3]) + gnew = np.broadcast_to(gnew, [1, 3, 3]) SYM_PG_d_laue = np.concatenate((SYM_PG_d_laue, gnew)) nsym += 1 @@ -295,6 +297,7 @@ def isnew(mat, sym_mats): return False return True + def latticeType(sgnum): if(sgnum <= 2): @@ -309,7 +312,7 @@ def latticeType(sgnum): return 'trigonal' elif(sgnum > 167 and sgnum <= 194): return 'hexagonal' - elif(sgnum > 194 and sgnum <=230): + elif(sgnum > 194 and sgnum <= 230): return 'cubic' else: raise RuntimeError('symmetry.latticeType: unknown space group number') @@ -323,14 +326,15 @@ def MakeGenerators_PGSYM(pggenstr): for any point group. this is needed for the coloring routines ''' ngen = int(pggenstr[0]) - SYM_GEN_PG = np.zeros([ngen,3,3]) + SYM_GEN_PG = np.zeros([ngen, 3, 3]) for i in range(ngen): s = pggenstr[i+1] - SYM_GEN_PG[i,:,:] = constants.SYM_GENERATORS[s] + SYM_GEN_PG[i, :, :] = constants.SYM_GENERATORS[s] return SYM_GEN_PG + def GeneratePGSYM(pgsym): ''' @AUTHOR Saransh Singh, Lawrence Livermore National Lab, saransh1@llnl.gov @@ -345,7 +349,6 @@ def GeneratePGSYM(pgsym): generate the powers of the group ''' - ''' now go through the group actions and see if its a new matrix if it is then add it to the group @@ -353,14 +356,14 @@ def GeneratePGSYM(pgsym): nsym = SYM_GEN_PG.shape[0] k1 = 0 while k1 < nsym: - g1 = np.squeeze(SYM_GEN_PG[k1,:,:]) + g1 = np.squeeze(SYM_GEN_PG[k1, :, :]) k2 = k1 while k2 < nsym: - g2 = np.squeeze(SYM_GEN_PG[k2,:,:]) + g2 = np.squeeze(SYM_GEN_PG[k2, :, :]) gnew = np.dot(g1, g2) if(isnew(gnew, SYM_GEN_PG)): - gnew = np.broadcast_to(gnew, [1,3,3]) + gnew = np.broadcast_to(gnew, [1, 3, 3]) SYM_GEN_PG = np.concatenate((SYM_GEN_PG, gnew)) nsym += 1 From f0f6c1b3da1ff7b08ab45390bd5f23a10df13e41 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Tue, 20 Aug 2024 11:46:44 -0700 Subject: [PATCH 05/10] more PEP8 --- hexrd/material/symbols.py | 278 ++++++++++++++++++++------------------ 1 file changed, 144 insertions(+), 134 deletions(-) diff --git a/hexrd/material/symbols.py b/hexrd/material/symbols.py index 18d8479b..200ae37c 100644 --- a/hexrd/material/symbols.py +++ b/hexrd/material/symbols.py @@ -1,6 +1,5 @@ pstr_mkxtal = "\n\n This is a program to create a HDF5 file for storing crystallographic information.\n " -pstr_mkxtal = pstr_mkxtal + " This format is the same format as used in the EMsoft (electron microscoy) suite.\n " pstr_mkxtal = pstr_mkxtal + " The following inputs are required:\n " pstr_mkxtal = pstr_mkxtal + " Crystal System:\n" pstr_mkxtal = pstr_mkxtal + " 1. Cubic\n" @@ -24,88 +23,98 @@ pstr_mkxtal = pstr_mkxtal + " trigonal symmetry is the hexagonal setting. When you select\n" pstr_mkxtal = pstr_mkxtal + " crystal system 5 above, you will be prompted for the setting. \n" -pstr_spacegroup = [ " P 1 " ," P -1 ", \ -# MONOCLINIC SPACE GROUPS -" P 2 " ," P 21 " ," C 2 " ," P m ", \ -" P c " ," C m " ," C c " ," P 2/m ", \ -" P 21/m " ," C 2/m " ," P 2/c " ," P 21/c ", \ -" C 2/c ", \ -# ORTHORHOMBIC SPACE GROUPS -" P 2 2 2 " ," P 2 2 21 " ," P 21 21 2 " ," P 21 21 21", \ -" C 2 2 21 " ," C 2 2 2 " ," F 2 2 2 " ," I 2 2 2 ", \ -" I 21 21 21" ," P m m 2 " ," P m c 21 " ," P c c 2 ", \ -" P m a 2 " ," P c a 21 " ," P n c 2 " ," P m n 21 ", \ -" P b a 2 " ," P n a 21 " ," P n n 2 " ," C m m 2 ", \ -" C m c 21 " ," C c c 2 " ," A m m 2 " ," A b m 2 ", \ -" A m a 2 " ," A b a 2 " ," F m m 2 " ," F d d 2 ", \ -" I m m 2 " ," I b a 2 " ," I m a 2 " ," P m m m ", \ -" P n n n " ," P c c m " ," P b a n " ," P m m a ", \ -" P n n a " ," P m n a " ," P c c a " ," P b a m ", \ -" P c c n " ," P b c m " ," P n n m " ," P m m n ", \ -" P b c n " ," P b c a " ," P n m a " ," C m c m ", \ -" C m c a " ," C m m m " ," C c c m " ," C m m a ", \ -" C c c a " ," F m m m " ," F d d d " ," I m m m ", \ -" I b a m " ," I b c a " ," I m m a ", \ -# TETRAGONAL SPACE GROUPS -" P 4 " ," P 41 " ," P 42 " ," P 43 ", \ -" I 4 " ," I 41 " ," P -4 " ," I -4 ", \ -" P 4/m " ," P 42/m " ," P 4/n " ," P 42/n ", \ -" I 4/m " ," I 41/a " ," P 4 2 2 " ," P 4 21 2 ", \ -" P 41 2 2 " ," P 41 21 2 " ," P 42 2 2 " ," P 42 21 2 ", \ -" P 43 2 2 " ," P 43 21 2 " ," I 4 2 2 " ," I 41 2 2 ", \ -" P 4 m m " ," P 4 b m " ," P 42 c m " ," P 42 n m ", \ -" P 4 c c " ," P 4 n c " ," P 42 m c " ," P 42 b c ", \ -" I 4 m m " ," I 4 c m " ," I 41 m d " ," I 41 c d ", \ -" P -4 2 m " ," P -4 2 c " ," P -4 21 m " ," P -4 21 c ", \ -" P -4 m 2 " ," P -4 c 2 " ," P -4 b 2 " ," P -4 n 2 ", \ -" I -4 m 2 " ," I -4 c 2 " ," I -4 2 m " ," I -4 2 d ", \ -" P 4/m m m " ," P 4/m c c " ," P 4/n b m " ," P 4/n n c ", \ -" P 4/m b m " ," P 4/m n c " ," P 4/n m m " ," P 4/n c c ", \ -" P 42/m m c" ," P 42/m c m" ," P 42/n b c" ," P 42/n n m", \ -" P 42/m b c" ," P 42/m n m" ," P 42/n m c" ," P 42/n c m", \ -" I 4/m m m " ," I 4/m c m " ," I 41/a m d" ," I 41/a c d", \ -# RHOMBOHEDRAL SPACE GROUPS -" P 3 " ," P 31 " ," P 32 " ," R 3 ", \ -" P -3 " ," R -3 " ," P 3 1 2 " ," P 3 2 1 ", \ -" P 31 1 2 " ," P 31 2 1 " ," P 32 1 2 " ," P 32 2 1 ", \ -" R 3 2 " ," P 3 m 1 " ," P 3 1 m " ," P 3 c 1 ", \ -" P 3 1 c " ," R 3 m " ," R 3 c " ," P -3 1 m ", \ -" P -3 1 c " ," P -3 m 1 " ," P -3 c 1 " ," R -3 m ", \ -" R -3 c ", \ -# HEXAGONAL SPACE GROUPS -" P 6 " ," P 61 " ," P 65 " ," P 62 ", \ -" P 64 " ," P 63 " ," P -6 " ," P 6/m ", \ -" P 63/m " ," P 6 2 2 " ," P 61 2 2 " ," P 65 2 2 ", \ -" P 62 2 2 " ," P 64 2 2 " ," P 63 2 2 " ," P 6 m m ", \ -" P 6 c c " ," P 63 c m " ," P 63 m c " ," P -6 m 2 ", \ -" P -6 c 2 " ," P -6 2 m " ," P -6 2 c " ," P 6/m m m ", \ -" P 6/m c c " ," P 63/m c m" ," P 63/m m c", \ -#CUBIC SPACE GROUPS -" P 2 3 " ," F 2 3 " ," I 2 3 " ," P 21 3 ", \ -" I 21 3 " ," P m 3 " ," P n 3 " ," F m 3 ", \ -" F d 3 " ," I m 3 " ," P a 3 " ," I a 3 ", \ -" P 4 3 2 " ," P 42 3 2 " ," F 4 3 2 " ," F 41 3 2 ", \ -" I 4 3 2 " ," P 43 3 2 " ," P 41 3 2 " ," I 41 3 2 ", \ -" P -4 3 m " ," F -4 3 m " ," I -4 3 m " ," P -4 3 n ", \ -" F -4 3 c " ," I -4 3 d " ," P m 3 m " ," P n 3 n ", \ -" P m 3 n " ," P n 3 m " ," F m 3 m " ," F m 3 c ", \ -" F d 3 m " ," F d 3 c " ," I m 3 m " ," I a 3 d ", \ -# TRIGONAL GROUPS RHOMBOHEDRAL SETTING -" R 3 |146" ," R -3 |148" ," R 3 2 |155" ," R 3 m |160", \ -" R 3 c |161" ," R -3 m|166" ," R -3 c|167"] +pstr_spacegroup = +[ + " P 1 ", " P -1 ", \ + # MONOCLINIC SPACE GROUPS + " P 2 ", " P 21 ", " C 2 ", " P m ", \ + " P c ", " C m ", " C c ", " P 2/m ", \ + " P 21/m ", " C 2/m ", " P 2/c ", " P 21/c ", \ + " C 2/c ", \ + # ORTHORHOMBIC SPACE GROUPS + " P 2 2 2 ", " P 2 2 21 ", " P 21 21 2 ", " P 21 21 21", \ + " C 2 2 21 ", " C 2 2 2 ", " F 2 2 2 ", " I 2 2 2 ", \ + " I 21 21 21", " P m m 2 ", " P m c 21 ", " P c c 2 ", \ + " P m a 2 ", " P c a 21 ", " P n c 2 ", " P m n 21 ", \ + " P b a 2 ", " P n a 21 ", " P n n 2 ", " C m m 2 ", \ + " C m c 21 ", " C c c 2 ", " A m m 2 ", " A b m 2 ", \ + " A m a 2 ", " A b a 2 ", " F m m 2 ", " F d d 2 ", \ + " I m m 2 ", " I b a 2 ", " I m a 2 ", " P m m m ", \ + " P n n n ", " P c c m ", " P b a n ", " P m m a ", \ + " P n n a ", " P m n a ", " P c c a ", " P b a m ", \ + " P c c n ", " P b c m ", " P n n m ", " P m m n ", \ + " P b c n ", " P b c a ", " P n m a ", " C m c m ", \ + " C m c a ", " C m m m ", " C c c m ", " C m m a ", \ + " C c c a ", " F m m m ", " F d d d ", " I m m m ", \ + " I b a m ", " I b c a ", " I m m a ", \ + # TETRAGONAL SPACE GROUPS + " P 4 ", " P 41 ", " P 42 ", " P 43 ", \ + " I 4 ", " I 41 ", " P -4 ", " I -4 ", \ + " P 4/m ", " P 42/m ", " P 4/n ", " P 42/n ", \ + " I 4/m ", " I 41/a ", " P 4 2 2 ", " P 4 21 2 ", \ + " P 41 2 2 ", " P 41 21 2 ", " P 42 2 2 ", " P 42 21 2 ", \ + " P 43 2 2 ", " P 43 21 2 ", " I 4 2 2 ", " I 41 2 2 ", \ + " P 4 m m ", " P 4 b m ", " P 42 c m ", " P 42 n m ", \ + " P 4 c c ", " P 4 n c ", " P 42 m c ", " P 42 b c ", \ + " I 4 m m ", " I 4 c m ", " I 41 m d ", " I 41 c d ", \ + " P -4 2 m ", " P -4 2 c ", " P -4 21 m ", " P -4 21 c ", \ + " P -4 m 2 ", " P -4 c 2 ", " P -4 b 2 ", " P -4 n 2 ", \ + " I -4 m 2 ", " I -4 c 2 ", " I -4 2 m ", " I -4 2 d ", \ + " P 4/m m m ", " P 4/m c c ", " P 4/n b m ", " P 4/n n c ", \ + " P 4/m b m ", " P 4/m n c ", " P 4/n m m ", " P 4/n c c ", \ + " P 42/m m c", " P 42/m c m", " P 42/n b c", " P 42/n n m", \ + " P 42/m b c", " P 42/m n m", " P 42/n m c", " P 42/n c m", \ + " I 4/m m m ", " I 4/m c m ", " I 41/a m d", " I 41/a c d", \ + # RHOMBOHEDRAL SPACE GROUPS + " P 3 ", " P 31 ", " P 32 ", " R 3 ", \ + " P -3 ", " R -3 ", " P 3 1 2 ", " P 3 2 1 ", \ + " P 31 1 2 ", " P 31 2 1 ", " P 32 1 2 ", " P 32 2 1 ", \ + " R 3 2 ", " P 3 m 1 ", " P 3 1 m ", " P 3 c 1 ", \ + " P 3 1 c ", " R 3 m ", " R 3 c ", " P -3 1 m ", \ + " P -3 1 c ", " P -3 m 1 ", " P -3 c 1 ", " R -3 m ", \ + " R -3 c ", \ + # HEXAGONAL SPACE GROUPS + " P 6 ", " P 61 ", " P 65 ", " P 62 ", \ + " P 64 ", " P 63 ", " P -6 ", " P 6/m ", \ + " P 63/m ", " P 6 2 2 ", " P 61 2 2 ", " P 65 2 2 ", \ + " P 62 2 2 ", " P 64 2 2 ", " P 63 2 2 ", " P 6 m m ", \ + " P 6 c c ", " P 63 c m ", " P 63 m c ", " P -6 m 2 ", \ + " P -6 c 2 ", " P -6 2 m ", " P -6 2 c ", " P 6/m m m ", \ + " P 6/m c c ", " P 63/m c m", " P 63/m m c", \ + # CUBIC SPACE GROUPS + " P 2 3 ", " F 2 3 ", " I 2 3 ", " P 21 3 ", \ + " I 21 3 ", " P m 3 ", " P n 3 ", " F m 3 ", \ + " F d 3 ", " I m 3 ", " P a 3 ", " I a 3 ", \ + " P 4 3 2 ", " P 42 3 2 ", " F 4 3 2 ", " F 41 3 2 ", \ + " I 4 3 2 ", " P 43 3 2 ", " P 41 3 2 ", " I 41 3 2 ", \ + " P -4 3 m ", " F -4 3 m ", " I -4 3 m ", " P -4 3 n ", \ + " F -4 3 c ", " I -4 3 d ", " P m 3 m ", " P n 3 n ", \ + " P m 3 n ", " P n 3 m ", " F m 3 m ", " F m 3 c ", \ + " F d 3 m ", " F d 3 c ", " I m 3 m ", " I a 3 d ", \ + # TRIGONAL GROUPS RHOMBOHEDRAL SETTING + " R 3 |146", " R -3 |148", " R 3 2 |155", " R 3 m |160", \ + " R 3 c |161", " R -3 m|166", " R -3 c|167" +] -xtal_dict = {1:'cubic', 2:'tetragonal', 3:'orthorhombic', 4:'hexagonal', 5:'trigonal', 6:'monoclinic', 7:'triclinic'} -xtal_sys_dict = {'cubic':1, 'tetragonal':2, 'orthorhombic':3, 'hexagonal':4, 'trigonal':5, 'monoclinic':6, 'triclinic':7} +xtal_dict = {1: 'cubic', 2: 'tetragonal', 3: 'orthorhombic', + 4: 'hexagonal', 5: 'trigonal', 6: 'monoclinic', + 7: 'triclinic'} +xtal_sys_dict = {'cubic': 1, 'tetragonal': 2, 'orthorhombic': 3, + 'hexagonal': 4, 'trigonal': 5, 'monoclinic': 6, + 'triclinic': 7} -pstr_pointgroup = [' 1',' -1',' 2',' m',' 2/m',' 222', \ -' mm2',' mmm',' 4',' -4',' 4/m',' 422', \ -' 4mm',' -42m','4/mmm',' 3',' -3',' 32', \ -' 3m',' -3m',' 6',' -6',' 6/m',' 622', \ -' 6mm',' -6m2','6/mmm',' 23',' m3',' 432', \ -' -43m',' m-3m',' 532',' 822',' 1022',' 1222' ] -TRIG = [146,148,155,160,161,166,167] + +pstr_pointgroup = [' 1', ' -1', ' 2', ' m', ' 2/m', ' 222', + ' mm2', ' mmm', ' 4', ' -4', ' 4/m', ' 422', + ' 4mm', ' -42m', '4/mmm', ' 3', ' -3', ' 32', + ' 3m', ' -3m', ' 6', ' -6', ' 6/m', ' 622', + ' 6mm', ' -6m2', '6/mmm', ' 23', ' m3', ' 432', + ' -43m', ' m-3m', ' 532', ' 822', ' 1022', ' 1222'] + +TRIG = [146, 148, 155, 160, 161, 166, 167] + # symbols and Z for all elements pstr_Elements = ' ------------------------------------ Periodic Table of the Elements --------------------------------------' + "\n" \ @@ -126,66 +135,66 @@ groups ''' two_origin_choice = { -48 : ['222', '-1'], -50 : ['222/n', '-1'], -59 : ['mm2/n', '-1'], -68 : ['222', '-1'], -70 : ['222', '-1'], -85 : ['-4', '-1'], -86 : ['-4', '-1'], -88 : ['-4', '-1'], -125: ['422', '2/m'], -126: ['422/n', '-1'], -129: ['-4m2', '2/m'], -130: ['-4/ncn', '-1'], -133: ['-4121/c', '-1'], -134: ['-42m', '2/m'], -137: ['-4m2/n', '-1'], -138: ['-4cg', '2/m'], -141: ['-4m2', '2/m'], -142: ['-4c21', '-1'], -201: ['23', '-3'], -203: ['23', '-3'], -222: ['432', '-3'], -224: ['-43m', '-3m'], -227: ['-43m', '-3m'], -228: ['23', '-3'], + 48: ['222', '-1'], + 50: ['222/n', '-1'], + 59: ['mm2/n', '-1'], + 68: ['222', '-1'], + 70: ['222', '-1'], + 85: ['-4', '-1'], + 86: ['-4', '-1'], + 88: ['-4', '-1'], + 125: ['422', '2/m'], + 126: ['422/n', '-1'], + 129: ['-4m2', '2/m'], + 130: ['-4/ncn', '-1'], + 133: ['-4121/c', '-1'], + 134: ['-42m', '2/m'], + 137: ['-4m2/n', '-1'], + 138: ['-4cg', '2/m'], + 141: ['-4m2', '2/m'], + 142: ['-4c21', '-1'], + 201: ['23', '-3'], + 203: ['23', '-3'], + 222: ['432', '-3'], + 224: ['-43m', '-3m'], + 227: ['-43m', '-3m'], + 228: ['23', '-3'], } def PrintPossibleSG(xtal_sys): - if(xtal_sys == 1): - sgmax = 230 - sgmin = 195 - elif(xtal_sys == 2): - sgmax = 142 - sgmin = 75 - elif(xtal_sys == 3): - sgmax = 74 - sgmin = 16 - elif(xtal_sys == 4): - sgmax = 194 - sgmin = 168 - elif(xtal_sys == 5): - sgmax = 167 - sgmin = 143 - elif(xtal_sys == 6): - sgmax = 15 - sgmin = 3 - elif(xtal_sys == 7): - sgmax = 2 - sgmin = 1 + if(xtal_sys == 1): + sgmax = 230 + sgmin = 195 + elif(xtal_sys == 2): + sgmax = 142 + sgmin = 75 + elif(xtal_sys == 3): + sgmax = 74 + sgmin = 16 + elif(xtal_sys == 4): + sgmax = 194 + sgmin = 168 + elif(xtal_sys == 5): + sgmax = 167 + sgmin = 143 + elif(xtal_sys == 6): + sgmax = 15 + sgmin = 3 + elif(xtal_sys == 7): + sgmax = 2 + sgmin = 1 - for i in range(sgmin,sgmax+1): - j = i - sgmin + 1 - pstr = str(i) + ":" + pstr_spacegroup[i-1] + "\t" - if(j % 4 == 0 or j == sgmax): - print(pstr) - else: - print(pstr, end='') - print("\n") + for i in range(sgmin, sgmax+1): + j = i - sgmin + 1 + pstr = str(i) + ":" + pstr_spacegroup[i-1] + "\t" + if(j % 4 == 0 or j == sgmax): + print(pstr) + else: + print(pstr, end='') + print("\n") - return sgmin, sgmax + return sgmin, sgmax # @@ -1257,6 +1266,7 @@ def PrintPossibleSG(xtal_sys): 230 I a -3 d """ + def _buildDict(hstr): """build the dictionaries from the notation string @@ -1267,7 +1277,7 @@ def _buildDict(hstr): for the rhombohedral lattices so that they use the hexagonal convention. """ - d = dict() + d = dict() di = dict() hs = hstr.split('\n') for l in hs: From 49432891c374aa85e8dbcd9d6269a151f1bcfdd2 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Tue, 20 Aug 2024 11:48:16 -0700 Subject: [PATCH 06/10] final few PEP8 --- hexrd/material/symbols.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/hexrd/material/symbols.py b/hexrd/material/symbols.py index 200ae37c..a2a2cae8 100644 --- a/hexrd/material/symbols.py +++ b/hexrd/material/symbols.py @@ -106,12 +106,16 @@ -pstr_pointgroup = [' 1', ' -1', ' 2', ' m', ' 2/m', ' 222', - ' mm2', ' mmm', ' 4', ' -4', ' 4/m', ' 422', - ' 4mm', ' -42m', '4/mmm', ' 3', ' -3', ' 32', - ' 3m', ' -3m', ' 6', ' -6', ' 6/m', ' 622', - ' 6mm', ' -6m2', '6/mmm', ' 23', ' m3', ' 432', - ' -43m', ' m-3m', ' 532', ' 822', ' 1022', ' 1222'] +pstr_pointgroup = +[ + ' 1', ' -1', ' 2', ' m', ' 2/m', ' 222', + ' mm2', ' mmm', ' 4', ' -4', ' 4/m', ' 422', + ' 4mm', ' -42m', '4/mmm', ' 3', ' -3', ' 32', + ' 3m', ' -3m', ' 6', ' -6', ' 6/m', ' 622', + ' 6mm', ' -6m2', '6/mmm', ' 23', ' m3', ' 432', + ' -43m', ' m-3m', ' 532', ' 822', ' 1022', ' 1222' +] + TRIG = [146, 148, 155, 160, 161, 166, 167] @@ -129,11 +133,12 @@ '89:Ac 90:Th 91:Pa 92:U' + "\n" \ ' ----------------------------------------------------------------------------------------------------------' -''' this dictionary contains the space group numbers +'''this dictionary contains the space group numbers which have two origin choices the two values are the site symmetries of the origin. There are 24 such space -groups -''' +groups''' + + two_origin_choice = { 48: ['222', '-1'], 50: ['222/n', '-1'], From 0d86fdc8b0856088c659a0bb75f82e061876a340 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Tue, 20 Aug 2024 11:52:01 -0700 Subject: [PATCH 07/10] accidentally introduced a typo --- hexrd/material/symbols.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hexrd/material/symbols.py b/hexrd/material/symbols.py index a2a2cae8..637a5136 100644 --- a/hexrd/material/symbols.py +++ b/hexrd/material/symbols.py @@ -23,8 +23,7 @@ pstr_mkxtal = pstr_mkxtal + " trigonal symmetry is the hexagonal setting. When you select\n" pstr_mkxtal = pstr_mkxtal + " crystal system 5 above, you will be prompted for the setting. \n" -pstr_spacegroup = -[ +pstr_spacegroup = [ " P 1 ", " P -1 ", \ # MONOCLINIC SPACE GROUPS " P 2 ", " P 21 ", " C 2 ", " P m ", \ @@ -93,8 +92,8 @@ " F d 3 m ", " F d 3 c ", " I m 3 m ", " I a 3 d ", \ # TRIGONAL GROUPS RHOMBOHEDRAL SETTING " R 3 |146", " R -3 |148", " R 3 2 |155", " R 3 m |160", \ - " R 3 c |161", " R -3 m|166", " R -3 c|167" -] + " R 3 c |161", " R -3 m|166", " R -3 c|167"] + xtal_dict = {1: 'cubic', 2: 'tetragonal', 3: 'orthorhombic', @@ -106,15 +105,14 @@ -pstr_pointgroup = -[ +pstr_pointgroup = [ ' 1', ' -1', ' 2', ' m', ' 2/m', ' 222', ' mm2', ' mmm', ' 4', ' -4', ' 4/m', ' 422', ' 4mm', ' -42m', '4/mmm', ' 3', ' -3', ' 32', ' 3m', ' -3m', ' 6', ' -6', ' 6/m', ' 622', ' 6mm', ' -6m2', '6/mmm', ' 23', ' m3', ' 432', - ' -43m', ' m-3m', ' 532', ' 822', ' 1022', ' 1222' -] + ' -43m', ' m-3m', ' 532', ' 822', ' 1022', ' 1222'] + TRIG = [146, 148, 155, 160, 161, 166, 167] From ae5bb6b2eba1ddfbf5e72270053ed1a964f84b6c Mon Sep 17 00:00:00 2001 From: Zack Date: Tue, 20 Aug 2024 15:05:38 -0400 Subject: [PATCH 08/10] Resolve compiler flags for Windows (#706) * Resolve compiler flags for Windows * Remove cpp std identifier * Update pyproject * Re-add std c++14 * Specify c++14 only for c++, not c * Remove erroneous c++ std annotation * Remove changes to setuptools_scm version scheme These were not actually necessary to fix the mac packaging after all. Signed-off-by: Patrick Avery --------- Signed-off-by: Patrick Avery Co-authored-by: Patrick Avery --- setup.py | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/setup.py b/setup.py index 88a5b63e..ae91a962 100644 --- a/setup.py +++ b/setup.py @@ -34,37 +34,36 @@ # Add it to the requirements automatically for intel computers. install_reqs.append('tbb') -# This will determine which compiler is being used to build the C modules +# Determine which compiler is being used to build the C/C++ modules compiler_type = distutils.ccompiler.get_default_compiler() if compiler_type in ("unix", "mingw32"): - compiler_optimize_flags = ['-O3', '-ftree-vectorize'] + compiler_flags = ['-O3', '-ftree-vectorize', '-Wall', '-funroll-loops'] + if not sys.platform.startswith('win'): + compiler_flags.append('-fPIC') elif compiler_type == "msvc": - compiler_optimize_flags = ['/Ox', '/GL'] + compiler_flags = ['/Ox', '/GL', '/std:c++14'] else: - compiler_optimize_flags = [] - + compiler_flags = [] -# extension for convolution from astropy +# Extension for convolution from astropy def get_convolution_extensions(): c_convolve_pkgdir = Path('hexrd') / 'convolution' src_files = [str(c_convolve_pkgdir / 'src/convolve.c')] - extra_compile_args = ['-UNDEBUG'] - if not sys.platform.startswith('win'): - extra_compile_args.append('-fPIC') - extra_compile_args += compiler_optimize_flags + extra_compile_args = ['-UNDEBUG'] + compiler_flags # Add '-Rpass-missed=.*' to ``extra_compile_args`` when compiling with # clang to report missed optimizations - _convolve_ext = Extension(name='hexrd.convolution._convolve', - sources=src_files, - extra_compile_args=extra_compile_args, - include_dirs=[numpy.get_include()], - language='c') + _convolve_ext = Extension( + name='hexrd.convolution._convolve', + sources=src_files, + extra_compile_args=extra_compile_args, + include_dirs=[numpy.get_include()], + language='c' + ) return [_convolve_ext] - def get_include_path(library_name): env_var_hint = os.getenv(f"{library_name.upper()}_INCLUDE_DIR") if env_var_hint is not None and os.path.exists(env_var_hint): @@ -97,7 +96,6 @@ def get_include_path(library_name): # It should exist now return full_path - def get_pybind11_include_path(): # If we can import pybind11, use that include path try: @@ -110,16 +108,10 @@ def get_pybind11_include_path(): # Otherwise, we will download the source and include that return get_include_path('pybind11') - def get_cpp_extensions(): cpp_transform_pkgdir = Path('hexrd') / 'transforms/cpp_sublibrary' src_files = [str(cpp_transform_pkgdir / 'src/inverse_distortion.cpp')] - extra_compile_args = ['-O3', '-Wall', '-shared', '-std=c++14', - '-funroll-loops'] - if not sys.platform.startswith('win'): - extra_compile_args.append('-fPIC') - # Define include directories include_dirs = [ get_include_path('xsimd'), @@ -131,14 +123,13 @@ def get_cpp_extensions(): inverse_distortion_ext = Extension( name='hexrd.extensions.inverse_distortion', sources=src_files, - extra_compile_args=extra_compile_args, + extra_compile_args=compiler_flags+['-std=c++14'], include_dirs=include_dirs, language='c++', ) return [inverse_distortion_ext] - def get_old_xfcapi_extension_modules(): # for transforms srclist = ['transforms_CAPI.c', 'transforms_CFUNC.c'] @@ -147,23 +138,21 @@ def get_old_xfcapi_extension_modules(): 'hexrd.extensions._transforms_CAPI', sources=srclist, include_dirs=[np_include_dir], - extra_compile_args=compiler_optimize_flags, + extra_compile_args=compiler_flags, ) return [transforms_mod] - def get_new_xfcapi_extension_modules(): transforms_mod = Extension( 'hexrd.extensions._new_transforms_capi', sources=['hexrd/transforms/new_capi/module.c'], include_dirs=[np_include_dir], - extra_compile_args=compiler_optimize_flags, + extra_compile_args=compiler_flags, ) return [transforms_mod] - def get_extension_modules(): # Flatten the lists return [item for sublist in ( @@ -173,7 +162,6 @@ def get_extension_modules(): get_cpp_extensions(), ) for item in sublist] - ext_modules = get_extension_modules() # use entry_points, not scripts: From 79c89837b306e5413666ab13cf1e3c67b1e1c9e2 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Tue, 20 Aug 2024 13:06:21 -0700 Subject: [PATCH 09/10] only select setting 2 by default if crystal is cubic e.g. diamond, silicon etc. --- hexrd/material/material.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hexrd/material/material.py b/hexrd/material/material.py index b447c6fd..df85eee6 100644 --- a/hexrd/material/material.py +++ b/hexrd/material/material.py @@ -81,10 +81,13 @@ def _key(x): def get_default_sgsetting(sgnum): + setting = 0 if sgnum in two_origin_choice: - return 1 - else: - return 0 + # only set cubic materials + # in the second setting by default + if sgnum > 194: + setting = 1 + return setting # # ---------------------------------------------------CLASS: Material From 3601b9f32a6bbaa65caeaad6e229b5f612964108 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Tue, 20 Aug 2024 13:43:14 -0700 Subject: [PATCH 10/10] roll back changes to default space group setting, and modify tests to only assume setting 1 --- hexrd/material/material.py | 9 +++------ tests/planedata/test_with_data.py | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/hexrd/material/material.py b/hexrd/material/material.py index df85eee6..b447c6fd 100644 --- a/hexrd/material/material.py +++ b/hexrd/material/material.py @@ -81,13 +81,10 @@ def _key(x): def get_default_sgsetting(sgnum): - setting = 0 if sgnum in two_origin_choice: - # only set cubic materials - # in the second setting by default - if sgnum > 194: - setting = 1 - return setting + return 1 + else: + return 0 # # ---------------------------------------------------CLASS: Material diff --git a/tests/planedata/test_with_data.py b/tests/planedata/test_with_data.py index b4e77179..0b4e9d53 100644 --- a/tests/planedata/test_with_data.py +++ b/tests/planedata/test_with_data.py @@ -24,7 +24,8 @@ def materials(test_data_dir): for mat_name in material_names: # Load {test_data_dir}/materials/{mat_name}.cif mat = Material( - mat_name, str(test_data_dir) + "/materials/" + mat_name + ".cif" + mat_name, str(test_data_dir) + "/materials/" + mat_name + ".cif", + sgsetting=0 ) mats[mat_name] = mat.planeData return mats