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

Import cross sections from csv #41

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0a0270c
add test for process_pdos
Jun 23, 2021
d5c8552
fix the imports
Yaxuan-Lii Jun 29, 2021
553738f
removeed irrelevant files
Yaxuan-Lii Jul 1, 2021
5300d62
import is fixed
Yaxuan-Lii Jul 1, 2021
dab091b
try to remove irrelevant fils second time
Yaxuan-Lii Jul 1, 2021
d69d61b
remove irrelevant files second time
Yaxuan-Lii Jul 1, 2021
7984c15
delet irrelevant files
Yaxuan-Lii Jul 1, 2021
66b1c6f
remove irrelevant files
Yaxuan-Lii Jul 1, 2021
4fdafa7
delete .DS_Store
Yaxuan-Lii Jul 1, 2021
dca2d49
Modified test_process_pdos.py
Yaxuan-Lii Jul 2, 2021
eb079f6
add test.py
Yaxuan-Lii Jul 2, 2021
8190183
Restore some files that were accidentally deleted
ajjackson Jul 2, 2021
946efaa
use flake8 to optimise format
Yaxuan-Lii Jul 5, 2021
cd0f3c0
import cross-sections from CSV archives
Yaxuan-Lii Jul 15, 2021
8f48e5e
form modify
Yaxuan-Lii Jul 17, 2021
a959150
modify follow the comments
Yaxuan-Lii Jul 21, 2021
067c289
make corrections
Yaxuan-Lii Jul 21, 2021
a621ab0
make correction
Yaxuan-Lii Jul 21, 2021
13911d0
Revert changes to galore/__init__.py
ajjackson Jul 21, 2021
4fb993d
modified as comments
Yaxuan-Lii Aug 2, 2021
cd4dc0e
merge the change of galore/__init__.py
Yaxuan-Lii Aug 2, 2021
5c9c31c
add cli to install data and get cross sections
Yaxuan-Lii Aug 9, 2021
b138c4b
merge get_cross_sections_from_csv into get_cross_sections
Yaxuan-Lii Aug 10, 2021
bb8a526
modify and add new test
Yaxuan-Lii Aug 24, 2021
5cdb67b
add a IF statement
Yaxuan-Lii Aug 31, 2021
39651d5
modify as comments
Yaxuan-Lii Sep 9, 2021
a2441b5
modify as comments
Yaxuan-Lii Sep 9, 2021
f59b50a
mistakes fix
Yaxuan-Lii Sep 12, 2021
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
70 changes: 46 additions & 24 deletions galore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@
from collections import OrderedDict
from collections.abc import Sequence
import logging
<<<<<<< HEAD

import galore.formats
=======
>>>>>>> 222f3f05787d36b754356ceb13dba854939c2d16
ajjackson marked this conversation as resolved.
Show resolved Hide resolved
from math import sqrt, log
import os.path

import numpy as np
from scipy.interpolate import interp1d

<<<<<<< HEAD
=======
import galore.formats
>>>>>>> 222f3f05787d36b754356ceb13dba854939c2d16
from galore.cross_sections import get_cross_sections, cross_sections_info
ajjackson marked this conversation as resolved.
Show resolved Hide resolved


Expand All @@ -52,9 +60,11 @@ def auto_limits(data_1d, padding=0.05):


def process_1d_data(input=['vasprun.xml'],
gaussian=None, lorentzian=None,
gaussian=None,
lorentzian=None,
sampling=1e-2,
xmin=None, xmax=None,
xmin=None,
xmax=None,
spikes=False,
**kwargs):
"""Read 1D data series from files, process for output
Expand Down Expand Up @@ -85,8 +95,7 @@ def process_1d_data(input=['vasprun.xml'],
input = input[0]

if not os.path.exists(input):
raise Exception(
"Input file {0} does not exist!".format(input))
raise Exception("Input file {0} does not exist!".format(input))
if galore.formats.is_xml(input):
xy_data = galore.formats.read_vasprun_totaldos(input)
elif galore.formats.is_gpw(input):
Expand All @@ -113,20 +122,29 @@ def process_1d_data(input=['vasprun.xml'],

broadened_data = data_1d.copy()
if lorentzian:
broadened_data = galore.broaden(
broadened_data, d=d, dist='lorentzian', width=lorentzian)
broadened_data = galore.broaden(broadened_data,
d=d,
dist='lorentzian',
width=lorentzian)

if gaussian:
broadened_data = galore.broaden(
broadened_data, d=d, dist='gaussian', width=gaussian)
broadened_data = galore.broaden(broadened_data,
d=d,
dist='gaussian',
width=gaussian)

return (x_values, broadened_data)


def process_pdos(input=['vasprun.xml'],
gaussian=None, lorentzian=None,
ajjackson marked this conversation as resolved.
Show resolved Hide resolved
weighting=None, sampling=1e-2,
xmin=None, xmax=None, flipx=False, **kwargs):
gaussian=None,
lorentzian=None,
weighting=None,
sampling=1e-2,
xmin=None,
xmax=None,
flipx=False,
**kwargs):
"""Read PDOS from files, process for output

Args:
Expand Down Expand Up @@ -167,8 +185,7 @@ def process_pdos(input=['vasprun.xml'],
break

if not os.path.exists(pdos_file):
raise Exception("Input file {0} does not "
"exist!".format(input))
raise Exception("Input file {0} does not " "exist!".format(input))

basename = os.path.basename(pdos_file)
try:
Expand All @@ -189,13 +206,14 @@ def process_pdos(input=['vasprun.xml'],
assert data.dtype.names[0] == energy_label
except AssertionError as error:
error.args += ("Energy labels are not consistent "
"between input files",)
"between input files", )
raise

orbital_labels = data.dtype.names[1:]
pdos_data[element] = OrderedDict([('energy', data[energy_label])])
pdos_data[element].update(OrderedDict((orbital, data[orbital])
for orbital in orbital_labels))
pdos_data[element].update(
OrderedDict(
(orbital, data[orbital]) for orbital in orbital_labels))
ajjackson marked this conversation as resolved.
Show resolved Hide resolved

# Work out sampling details; 5% pad added to data if no limits specified
# In x-flip mode, the user specifies these as binding energies so values
Expand Down Expand Up @@ -232,20 +250,22 @@ def process_pdos(input=['vasprun.xml'],
broadened_data = pdos_resampled.copy()

if lorentzian:
broadened_data = galore.broaden(broadened_data, d=d,
broadened_data = galore.broaden(broadened_data,
d=d,
dist='lorentzian',
width=lorentzian)

if gaussian:
broadened_data = galore.broaden(broadened_data, d=d,
broadened_data = galore.broaden(broadened_data,
d=d,
dist='gaussian',
width=gaussian)

pdos_plotting_data[element][orbital] = broadened_data

if weighting:
cross_sections = galore.get_cross_sections(weighting,
elements=pdos_data.keys())
cross_sections = get_cross_sections(weighting,
elements=pdos_data.keys())
pdos_plotting_data = galore.apply_orbital_weights(
pdos_plotting_data, cross_sections)

Expand Down Expand Up @@ -295,9 +315,11 @@ def xy_to_1d(xy, x_values, spikes=False):
return spikes

else:
y_func = interp1d(xy[x_field], xy[y_field],
y_func = interp1d(xy[x_field],
xy[y_field],
assume_sorted=False,
bounds_error=False, fill_value=0)
bounds_error=False,
fill_value=0)
return y_func(x_values)


Expand Down Expand Up @@ -417,8 +439,8 @@ def apply_orbital_weights(pdos_data, cross_sections):
weighted_pdos_data = OrderedDict()
for el, orbitals in pdos_data.items():
if 'warning' in cross_sections[el]:
logging.warning(" {0}: {1}".format(
el, cross_sections[el]['warning']))
logging.warning(" {0}: {1}".format(el,
cross_sections[el]['warning']))
weighted_orbitals = OrderedDict()
for orbital, data in orbitals.items():
if orbital == 'energy':
Expand Down
Loading