Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command line interface to make a new material #712

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hexrd/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from hexrd.cli import find_orientations
from hexrd.cli import fit_grains
from hexrd.cli import pickle23

from hexrd.cli import make_material

Check warning on line 19 in hexrd/cli/main.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/main.py#L19

Added line #L19 was not covered by tests

try:
_version = version("hexrd")
Expand Down Expand Up @@ -66,6 +66,7 @@
find_orientations.configure_parser(sub_parsers)
fit_grains.configure_parser(sub_parsers)
pickle23.configure_parser(sub_parsers)
make_material.configure_parser(sub_parsers)

Check warning on line 69 in hexrd/cli/main.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/main.py#L69

Added line #L69 was not covered by tests

try:
import argcomplete
Expand Down
39 changes: 39 additions & 0 deletions hexrd/cli/make_material.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys
from hexrd.cli import help

Check warning on line 2 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L1-L2

Added lines #L1 - L2 were not covered by tests

descr = (f'make a new material file in the '

Check warning on line 4 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L4

Added line #L4 was not covered by tests
f'hdf5 format using the command line. '
f'user specifies the file and crystal '
f'names')
example = """

Check warning on line 8 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L8

Added line #L8 was not covered by tests
examples:
hexrd make_material --file material.h5 --xtal diamond
"""


def configure_parser(sub_parsers):

Check warning on line 14 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L14

Added line #L14 was not covered by tests

p = sub_parsers.add_parser('make-material',

Check warning on line 16 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L16

Added line #L16 was not covered by tests
description=descr, help=descr)

p.add_argument(

Check warning on line 19 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L19

Added line #L19 was not covered by tests
'-f', '--file', type=str,
default='test.h5',
help='name of h5 file, default = test.h5'
)

p.add_argument(

Check warning on line 25 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L25

Added line #L25 was not covered by tests
'-x', '--xtal', type=str,
default='xtal',
help='name of crystal, default = xtal'
)

p.set_defaults(func=execute)

Check warning on line 31 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L31

Added line #L31 was not covered by tests


def execute(args, parser):
from hexrd.material.mksupport import mk

Check warning on line 35 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L34-L35

Added lines #L34 - L35 were not covered by tests

file = args.file
xtal = args.xtal
mk(file, xtal)

Check warning on line 39 in hexrd/cli/make_material.py

View check run for this annotation

Codecov / codecov/patch

hexrd/cli/make_material.py#L37-L39

Added lines #L37 - L39 were not covered by tests
37 changes: 24 additions & 13 deletions hexrd/material/mksupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import numpy as np
import datetime
import getpass
from hexrd.material.unitcell import _StiffnessDict, _pgDict
from hexrd.material.unitcell import (_StiffnessDict,
_pgDict,
unitcell_volume)



def mk(filename, xtalname):
Expand Down Expand Up @@ -330,8 +333,8 @@
def GetAsymmetricPositions(aniU):

asym = input(
"Enter asymmetric position of atom in unit cell \
separated by comma (fractional coordinates) : ")
f'Enter asymmetric position of atom in unit cell '
f'separated by comma (fractional coordinates) : ')
asym = [x.strip() for x in asym.split(',')]

for i, x in enumerate(asym):
Expand Down Expand Up @@ -483,7 +486,6 @@
material.h5 file output
@Date 01/14/2022 SS added tThWidth to materials file
"""

# Add the path prefix if we have been given one
if path is not None:
path = f"{path}/{AtomInfo['xtalname']}"
Expand Down Expand Up @@ -519,32 +521,41 @@
did = gid.create_dataset("stiffness", (6, 6), dtype=np.float64)
did.write_direct(np.array(AtomInfo['stiffness'], dtype=np.float64))

P = AtomInfo['pressure'] if 'pressure' in AtomInfo else 1.01325E-4 # 1 atm

Check warning on line 524 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L524

Added line #L524 was not covered by tests
did = gid.create_dataset("pressure", (1,), dtype=np.float64)
did.write_direct(np.array(AtomInfo['pressure'], dtype=np.float64))
did.write_direct(np.array(P, dtype=np.float64))

Check warning on line 526 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L526

Added line #L526 was not covered by tests

T = AtomInfo['temperature'] if 'temperature' in AtomInfo else 293 # R.T.

Check warning on line 528 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L528

Added line #L528 was not covered by tests
did = gid.create_dataset("temperature", (1,), dtype=np.float64)
did.write_direct(np.array(AtomInfo['temperature'], dtype=np.float64))
did.write_direct(np.array(T, dtype=np.float64))

Check warning on line 530 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L530

Added line #L530 was not covered by tests

k0 = AtomInfo['k0'] if 'k0' in AtomInfo else 100.0

Check warning on line 532 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L532

Added line #L532 was not covered by tests
did = gid.create_dataset("k0", (1,), dtype=np.float64)
did.write_direct(np.array([AtomInfo['k0']], dtype=np.float64))
did.write_direct(np.array([k0], dtype=np.float64))

Check warning on line 534 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L534

Added line #L534 was not covered by tests

k0p = AtomInfo['k0p'] if 'k0p' in AtomInfo else 0.0

Check warning on line 536 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L536

Added line #L536 was not covered by tests
did = gid.create_dataset("k0p", (1,), dtype=np.float64)
did.write_direct(np.array([AtomInfo['k0p']], dtype=np.float64))
did.write_direct(np.array([k0p], dtype=np.float64))

Check warning on line 538 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L538

Added line #L538 was not covered by tests

dk0dt = AtomInfo['dk0dt'] if 'dk0dt' in AtomInfo else 0.0

Check warning on line 540 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L540

Added line #L540 was not covered by tests
did = gid.create_dataset("dk0dt", (1,), dtype=np.float64)
did.write_direct(np.array([AtomInfo['dk0dt']], dtype=np.float64))
did.write_direct(np.array([dk0dt], dtype=np.float64))

Check warning on line 542 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L542

Added line #L542 was not covered by tests

dk0pdt = AtomInfo['dk0pdt'] if 'dk0pdt' in AtomInfo else 0.0

Check warning on line 544 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L544

Added line #L544 was not covered by tests
did = gid.create_dataset("dk0pdt", (1,), dtype=np.float64)
did.write_direct(np.array([AtomInfo['dk0pdt']], dtype=np.float64))
did.write_direct(np.array([dk0pdt], dtype=np.float64))

Check warning on line 546 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L546

Added line #L546 was not covered by tests

alpha_t = AtomInfo['alpha_t'] if 'alpha_t' in AtomInfo else 0.0

Check warning on line 548 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L548

Added line #L548 was not covered by tests
did = gid.create_dataset("alpha_t", (1,), dtype=np.float64)
did.write_direct(np.array([AtomInfo['alpha_t']], dtype=np.float64))
did.write_direct(np.array([alpha_t], dtype=np.float64))

Check warning on line 550 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L550

Added line #L550 was not covered by tests

dalpha_t_dt = AtomInfo['dalpha_t_dt'] if 'dalpha_t_dt' in AtomInfo else 0.0

Check warning on line 552 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L552

Added line #L552 was not covered by tests
did = gid.create_dataset("dalpha_t_dt", (1,), dtype=np.float64)
did.write_direct(np.array([AtomInfo['dalpha_t_dt']], dtype=np.float64))
did.write_direct(np.array([dalpha_t_dt], dtype=np.float64))

Check warning on line 554 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L554

Added line #L554 was not covered by tests

v0 = AtomInfo['v0'] if 'v0' in AtomInfo else unitcell_volume(lat_param)

Check warning on line 556 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L556

Added line #L556 was not covered by tests
did = gid.create_dataset("v0", (1,), dtype=np.float64)
did.write_direct(np.array([AtomInfo['v0']], dtype=np.float64))
did.write_direct(np.array([v0], dtype=np.float64))

Check warning on line 558 in hexrd/material/mksupport.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/mksupport.py#L558

Added line #L558 was not covered by tests

if "tThWidth" in AtomInfo:
did = gid.create_dataset("tThWidth", (1,), dtype=np.float64)
Expand Down
49 changes: 25 additions & 24 deletions hexrd/material/symbols.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@

pstr_mkxtal = "\n\n This is a program to create a HDF5 file for storing crystallographic information.\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"
pstr_mkxtal = pstr_mkxtal + " 2. Tetragonal\n"
pstr_mkxtal = pstr_mkxtal + " 3. Orthorhombic\n"
pstr_mkxtal = pstr_mkxtal + " 4. Hexagonal\n"
pstr_mkxtal = pstr_mkxtal + " 5. Trigonal\n"
pstr_mkxtal = pstr_mkxtal + " 6. Monoclinic\n"
pstr_mkxtal = pstr_mkxtal + " 7. Triclinic\n\n"
pstr_mkxtal = pstr_mkxtal + " Space group number\n"
pstr_mkxtal = pstr_mkxtal + " Atomic number (Z) for all species in unit cell\n"
pstr_mkxtal = pstr_mkxtal + " Asymmetric positions for all atoms in unit cell\n"
pstr_mkxtal = pstr_mkxtal + " Debye-Waller factors for all atoms in the unit cell\n"
pstr_mkxtal = pstr_mkxtal + " You'll be prompted for these values now\n\n"
pstr_mkxtal = pstr_mkxtal + "\n Note about the trigonal system:\n"
pstr_mkxtal = pstr_mkxtal + " -------------------------------\n"
pstr_mkxtal = pstr_mkxtal + " Primitive trigonal crystals are defined with respect to a HEXAGONAL\n"
pstr_mkxtal = pstr_mkxtal + " reference frame. Rhombohedral crystals can be referenced with\n"
pstr_mkxtal = pstr_mkxtal + " respect to a HEXAGONAL basis (first setting), or with respect to\n"
pstr_mkxtal = pstr_mkxtal + " a RHOMBOHEDRAL basis (second setting). The default setting for\n"
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_mkxtal = (
f'\n\n This is a program to create a HDF5 file for storing '
f'crystallographic information.\n'
f' The following inputs are required:\n '
f' Crystal System:\n'
f' 1. Cubic\n'
f' 2. Tetragonal\n'
f' 3. Orthorhombic\n'
f' 4. Hexagonal\n'
f' 5. Trigonal\n'
f' 6. Monoclinic\n'
f' 7. Triclinic\n\n'
f' Space group number\n'
f' Atomic number (Z) for all species in unit cell\n'
f' Asymmetric positions for all atoms in unit cell\n'
f' Debye-Waller factors for all atoms in the unit cell\n'
f' You\'ll be prompted for these values now \n\n'
f'\n Note about the trigonal system:\n'
f' -------------------------------\n'
f' Primitive trigonal crystals are defined with respect to a HEXAGONAL\n'
f' reference frame. Rhombohedral crystals can be referenced with\n'
f' respect to a HEXAGONAL basis (first setting), or with respect to\n'
f' a RHOMBOHEDRAL basis (second setting). The default setting for\n'
f' trigonal symmetry is the hexagonal setting. When you select\n'
f' crystal system 5 above, you will be prompted for the setting. \n')

pstr_spacegroup = [
" P 1 ", " P -1 ", \
Expand Down
13 changes: 13 additions & 0 deletions hexrd/material/unitcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@
return vsym


def unitcell_volume(lp):
'''helper function to explicitly compute unitcell
volume (in A^3) using the forula. the unitcell class
value is set using the determinant of the metric tensor
'''
ca = np.cos(np.radians(lp['alpha']))
cb = np.cos(np.radians(lp['beta']))
cg = np.cos(np.radians(lp['gamma']))

Check warning on line 59 in hexrd/material/unitcell.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/unitcell.py#L57-L59

Added lines #L57 - L59 were not covered by tests

fact = np.sqrt(1 - ca**2 - cb**2 - cg**2 + 2*ca*cb*cg)

Check warning on line 61 in hexrd/material/unitcell.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/unitcell.py#L61

Added line #L61 was not covered by tests
# 1E3 factor to go from nm to A
return lp['a']*lp['b']*lp['c']*fact*1E3

Check warning on line 63 in hexrd/material/unitcell.py

View check run for this annotation

Codecov / codecov/patch

hexrd/material/unitcell.py#L63

Added line #L63 was not covered by tests

class unitcell:

'''
Expand Down
Loading