Skip to content

Commit

Permalink
Merge branch 'master' into materials-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
saransh13 authored Aug 20, 2024
2 parents b7f2ef3 + 5f1f4c5 commit 6355483
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 242 deletions.
58 changes: 38 additions & 20 deletions hexrd/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -162,7 +163,9 @@
3628800.]).astype(np.complex128)

"""
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab, [email protected]
>> @AUTHOR: Saransh Singh,
Lawrence Livermore National Lab,
[email protected]
>> @DATE: 11/28/2022 SS 1.0 original
>> @DETAILS: constants for rodrigues FZ
"""
Expand All @@ -177,7 +180,9 @@
)

'''
>> @AUTHOR: Saransh Singh, Lawrence Livermore National Lab, [email protected]
>> @AUTHOR: Saransh Singh,
Lawrence Livermore National Lab,
[email protected]
>> @DATE: 10/28/2020 SS 1.0 original
>> @DETAILS: constants for sphere sectors used for IPF coloring
'''
Expand Down Expand Up @@ -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.
"""

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1100,17 +1114,21 @@ def is_writable_file(path):
SYM_GENERATORS['Y'] = -1./4.
SYM_GENERATORS['Z'] = -1./8.


'''
@AUTHOR Saransh Singh, Lawrence Livermore National Lab, [email protected]
@AUTHOR Saransh Singh,
Lawrence Livermore National Lab,
[email protected]
@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
Expand Down
33 changes: 20 additions & 13 deletions hexrd/material/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +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
from hexrd.constants import (ptable,
ptableinverse,
chargestate)

from os import path
from pathlib import Path
Expand Down Expand Up @@ -77,6 +80,12 @@ def _key(x):
return x.name


def get_default_sgsetting(sgnum):
if sgnum in two_origin_choice:
return 1
else:
return 0

#
# ---------------------------------------------------CLASS: Material
#
Expand Down Expand Up @@ -148,7 +157,7 @@ def __init__(
material_file=None,
dmin=None,
kev=None,
sgsetting=DFLT_SGSETTING,
sgsetting=None,
):
"""Constructor for Material
Expand All @@ -165,8 +174,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)):
Expand All @@ -180,6 +187,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
Expand All @@ -189,8 +199,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
#
Expand Down Expand Up @@ -645,6 +655,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
Expand Down Expand Up @@ -795,7 +806,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
Expand Down Expand Up @@ -864,6 +874,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
Expand All @@ -880,10 +893,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'))
Expand Down Expand Up @@ -1428,8 +1437,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.
Expand All @@ -1452,7 +1460,6 @@ def load_materials_hdf5(
'material_file': f,
'dmin': dmin,
'kev': kev,
'sgsetting': sgsetting,
}
return {name: Material(name, **kwargs) for name in names}

Expand Down
20 changes: 12 additions & 8 deletions hexrd/material/mksupport.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +14,7 @@
unitcell_volume)



def mk(filename, xtalname):

# print some initial information for the user
Expand Down Expand Up @@ -278,14 +282,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.")
Expand All @@ -297,7 +302,6 @@ def SpaceGroupSetting(sgnum):

return iset-1


def GetAtomInfo():

print(pstr_Elements)
Expand Down
Loading

0 comments on commit 6355483

Please sign in to comment.