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

Workshop fixes #114

Merged
merged 35 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7497775
Convert a Series to a frame through the to_frame method in Series
sudarshanv01 Aug 1, 2023
02d54b6
Implement to_frame for sequence of series
sudarshanv01 Aug 1, 2023
c557f72
Alter to_frame to allow it to take in multiple y-inputs
sudarshanv01 Aug 1, 2023
efca677
Refactor to_frame
sudarshanv01 Aug 1, 2023
9d180c7
Add width to series
sudarshanv01 Aug 1, 2023
18b268d
assert in to_frame that the dimension of weight and y is the same
sudarshanv01 Aug 2, 2023
0bd3f51
Allow different length series to to_frame
sudarshanv01 Aug 2, 2023
cda4814
Create the to_csv method
sudarshanv01 Aug 2, 2023
be04713
Implement to_csv method in the Mixin class
sudarshanv01 Aug 2, 2023
0b35fe1
Add to_csv and to_frame to the Mixin class
sudarshanv01 Aug 3, 2023
30b0b13
Apply black and isort
sudarshanv01 Aug 3, 2023
f5a4881
Added not_core to tests needing pandas
sudarshanv01 Aug 3, 2023
bafcb11
black and isort code formatting
sudarshanv01 Aug 3, 2023
b6db94c
Added more not_core to graph tests
sudarshanv01 Aug 3, 2023
ad66601
Change resolve to absolute when getting absolute path for mixin tests
sudarshanv01 Aug 3, 2023
92b51a4
Added documentation for the and methods
sudarshanv01 Aug 3, 2023
623124a
Update developer depedencies with ipykernel
sudarshanv01 Aug 3, 2023
bcb6f89
Merge branch 'vasp-dev:master' into master
sudarshanv01 Aug 3, 2023
a907827
Allow install github actions to run on pull requests
sudarshanv01 Aug 3, 2023
0d5838f
Merge branch 'master' of github.com:sudarshanv01/py4vasp
sudarshanv01 Aug 3, 2023
7f8739f
Added pip installation of ipykernel into install.yaml
sudarshanv01 Aug 3, 2023
f4f1515
Merge branch 'vasp-dev:master' into master
sudarshanv01 Aug 3, 2023
5c1240d
add pre-commit-config.yaml and pre-commit as a dependency
sudarshanv01 Aug 3, 2023
9a32998
Merge branch 'master' of github.com:sudarshanv01/py4vasp
sudarshanv01 Aug 3, 2023
0671d9e
Merge branch 'master' of github.com:vasp-dev/py4vasp
sudarshanv01 Sep 10, 2023
e5e244e
Merge branch 'master' of github.com:vasp-dev/py4vasp
sudarshanv01 Sep 25, 2023
f578627
Merge branch 'master' of github.com:vasp-dev/py4vasp
sudarshanv01 Oct 4, 2023
edd75dd
allow scale to be a numpy float
sudarshanv01 Oct 4, 2023
3b3fed5
Expose MLFFErrorAnalysis
sudarshanv01 Oct 4, 2023
17fdd32
Fix calling plot with keyword arguments
martin-schlipf Oct 5, 2023
92e93cd
fix string fix-length issue for MD energy plotting
sudarshanv01 Oct 5, 2023
786a2cc
Merge branch 'workshop-fixes' of github.com:vasp-dev/py4vasp into wor…
sudarshanv01 Oct 5, 2023
83296f3
Replace calculations import with py4vasp import
sudarshanv01 Oct 6, 2023
ededac8
Fix access to hdf5 files for trajectories
martin-schlipf Oct 6, 2023
cb367a5
Merge branch 'workshop-fixes' of github.com:vasp-dev/py4vasp into wor…
martin-schlipf Oct 6, 2023
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
1 change: 1 addition & 0 deletions src/py4vasp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright © VASP Software GmbH,
# Licensed under the Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
from py4vasp._analysis.mlff import MLFFErrorAnalysis
from py4vasp._calculation import Calculation
from py4vasp._calculations import Calculations
from py4vasp._third_party.graph import plot
Expand Down
11 changes: 8 additions & 3 deletions src/py4vasp/_analysis/mlff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import numpy as np

from py4vasp import Calculations, exception
import py4vasp
from py4vasp import exception


class MLFFErrorAnalysis:
Expand Down Expand Up @@ -71,7 +72,9 @@ def from_paths(cls, dft_data, mlff_data):
Path to the MLFF data. Accepts wildcards.
"""
mlff_error_analysis = cls(_internal=True)
calculations = Calculations.from_paths(dft_data=dft_data, mlff_data=mlff_data)
calculations = py4vasp.Calculations.from_paths(
dft_data=dft_data, mlff_data=mlff_data
)
mlff_error_analysis._calculations = calculations
set_appropriate_attrs(mlff_error_analysis)
return mlff_error_analysis
Expand All @@ -92,7 +95,9 @@ def from_files(cls, dft_data, mlff_data):
Path to the MLFF data. Accepts wildcards.
"""
mlff_error_analysis = cls(_internal=True)
calculations = Calculations.from_files(dft_data=dft_data, mlff_data=mlff_data)
calculations = py4vasp.Calculations.from_files(
dft_data=dft_data, mlff_data=mlff_data
)
mlff_error_analysis._calculations = calculations
set_appropriate_attrs(mlff_error_analysis)
return mlff_error_analysis
Expand Down
24 changes: 12 additions & 12 deletions src/py4vasp/_data/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def _selection_string(default):


_SELECTIONS = {
"ion-electron TOTEN ": ["ion_electron", "TOTEN"],
"kinetic energy EKIN ": ["kinetic_energy", "EKIN"],
"ion-electron TOTEN": ["ion_electron", "TOTEN"],
"kinetic energy EKIN": ["kinetic_energy", "EKIN"],
"kin. lattice EKIN_LAT": ["kinetic_lattice", "EKIN_LAT"],
"temperature TEIN ": ["temperature", "TEIN"],
"nose potential ES ": ["nose_potential", "ES"],
"nose kinetic EPS ": ["nose_kinetic", "EPS"],
"total energy ETOTAL ": ["total_energy", "ETOTAL"],
"free energy TOTEN ": ["free_energy", "TOTEN"],
"energy without entropy ": ["without_entropy", "ENOENT"],
"energy(sigma->0) ": ["sigma_0", "ESIG0"],
"temperature TEIN": ["temperature", "TEIN"],
"nose potential ES": ["nose_potential", "ES"],
"nose kinetic EPS": ["nose_kinetic", "EPS"],
"total energy ETOTAL": ["total_energy", "ETOTAL"],
"free energy TOTEN": ["free_energy", "TOTEN"],
"energy without entropy": ["without_entropy", "ENOENT"],
"energy(sigma->0)": ["sigma_0", "ESIG0"],
}


Expand Down Expand Up @@ -168,7 +168,7 @@ def _init_selection_dict(self):
return {
selection: index
for index, label in enumerate(self._raw_data.labels)
for selection in _SELECTIONS.get(convert.text_to_string(label), ())
for selection in _SELECTIONS.get(convert.text_to_string(label).strip(), ())
}

def _make_series(self, yaxes, tree):
Expand All @@ -188,9 +188,9 @@ def __init__(self, tree):
self.y2label = "Temperature (K)" if self.use_both else None

def _is_temperature(self, selection):
choices = _SELECTIONS["temperature TEIN "]
choices = _SELECTIONS["temperature TEIN"]
return any(select.contains(selection, choice) for choice in choices)

def use_y2(self, label):
choices = _SELECTIONS["temperature TEIN "]
choices = _SELECTIONS["temperature TEIN"]
return self.use_both and label in choices
3 changes: 3 additions & 0 deletions src/py4vasp/_data/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ def _lattice_vectors(self):
return self._scale() * lattice_vectors[self._get_steps()]

def _scale(self):
if isinstance(self._raw_data.cell.scale, np.float_):
return self._raw_data.cell.scale
if not self._raw_data.cell.scale.is_none():
return self._raw_data.cell.scale[()]
else:
Expand Down Expand Up @@ -324,6 +326,7 @@ def _step_string(self):
else:
return f" (step {self._steps + 1})"

@base.data_access
def __getitem__(self, steps):
if not self._is_trajectory:
message = "The structure is not a Trajectory so accessing individual elements is not allowed."
Expand Down
15 changes: 11 additions & 4 deletions src/py4vasp/_third_party/graph/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ def plot(*args, **kwargs):


def _parse_series(*args, **kwargs):
if series := _parse_multiple_series(*args, **kwargs):
return series
else:
return _parse_single_series(*args, **kwargs)


def _parse_multiple_series(*args, **kwargs):
try:
return [Series(*arg) for arg in args]
except TypeError:
# A TypeError is raised, if plot(x, y) is called instead of plot((x, y)).
# Because we creating the Series may raise another error, we leave the
# exception handling first to avoid reraising the TypeError.
pass
return []


def _parse_single_series(*args, **kwargs):
for_series = {key: val for key, val in kwargs.items() if key in Series._fields}
return Series(*args, **for_series)
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@ def _polarization():

def _MD_energy(randomize: bool = False):
labels = (
"ion-electron TOTEN ",
"kinetic energy EKIN ",
"ion-electron TOTEN",
"kinetic energy EKIN",
"kin. lattice EKIN_LAT",
"temperature TEIN ",
"nose potential ES ",
"nose kinetic EPS ",
"total energy ETOTAL ",
"temperature TEIN",
"nose potential ES",
"nose kinetic EPS",
"total energy ETOTAL",
)
return _create_energy(labels, randomize=randomize)

Expand Down
6 changes: 4 additions & 2 deletions tests/data/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def inner(cls, data, parameters={}):
def check_instance_accesses_data(instance, data, parameters, file=None):
failed = []
for name, method in inspect.getmembers(instance, inspect.ismethod):
if should_test_method(name):
if should_test_method(name, parameters):
kwargs = parameters.get(name, {})
try:
check_method_accesses_data(data, method, file, **kwargs)
Expand All @@ -50,7 +50,9 @@ def check_instance_accesses_data(instance, data, parameters, file=None):
raise AssertionError(message)


def should_test_method(name):
def should_test_method(name, parameters):
if name in parameters:
return True
if name in ("__str__", "_repr_html_"):
return True
if name.startswith("from") or name.startswith("_"):
Expand Down
3 changes: 2 additions & 1 deletion tests/data/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,5 @@ def test_print_Ca3AsBr3(Ca3AsBr3, format_):

def test_factory_methods(raw_data, check_factory_methods):
data = raw_data.structure("Sr2TiO4")
check_factory_methods(Structure, data)
parameters = {"__getitem__": {"steps": slice(None)}}
check_factory_methods(Structure, data, parameters)
2 changes: 2 additions & 0 deletions tests/third_party/graph/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_plot():
assert plot((x1, y1)) == Graph([series0])
assert plot((x1, y1), (x2, y2, "label2")) == Graph([series0, series2])
assert plot((x1, y1), xlabel="xaxis") == Graph([series0], xlabel="xaxis")
assert plot(x1, y=y1) == Graph(series0)
assert plot(x=x1, y=y1) == Graph(series0)


def test_plot_small_dataset():
Expand Down