Skip to content

Commit

Permalink
merge devel to master for v0.2.18 (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz authored Apr 3, 2024
2 parents e2f235f + 4daf372 commit 658a511
Show file tree
Hide file tree
Showing 69 changed files with 9,323 additions and 68 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
target-branch: "devel"
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.12"]

steps:
- uses: actions/checkout@v2
Expand All @@ -26,7 +26,9 @@ jobs:
- name: Test
run: cd tests && coverage run --source=../dpdata -m unittest && cd .. && coverage combine tests/.coverage && coverage report
- name: Run codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
pass:
needs: [build]
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ docs/drivers.csv
docs/minimizers.csv
docs/api/
docs/formats/
.DS_Store
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ repos:
- id: check-symlinks
- id: check-toml
# Python
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.3
rev: v0.3.5
hooks:
- id: ruff
args: ["--fix"]
types_or: [python, pyi, jupyter]
- id: ruff-format
types_or: [python, pyi, jupyter]
# numpydoc
- repo: https://github.com/Carreau/velin
rev: 0.0.12
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
prune docs
prune tests
prune plugin_example
9 changes: 5 additions & 4 deletions docs/make_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ def generate_sub_format_pages(formats: dict):
buff.append(""" :noindex:""")
buff.append("")
if docstring is None or method not in format.__dict__:
docstring = """ Convert this format to :class:`%s`.""" % (
method_classes[method]
docstring = (
""" Convert this format to :class:`%s`."""
% (method_classes[method])
)
doc_obj = SphinxDocString(docstring)
if len(doc_obj["Parameters"]) > 0:
Expand Down Expand Up @@ -293,8 +294,8 @@ def generate_sub_format_pages(formats: dict):
and "to_system" in format.__dict__
)
):
docstring = "Convert :class:`%s` to this format." % (
method_classes[method]
docstring = (
"Convert :class:`%s` to this format." % (method_classes[method])
)
doc_obj = SphinxDocString(docstring)
if len(doc_obj["Parameters"]) > 0:
Expand Down
39 changes: 36 additions & 3 deletions dpdata/abacus/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
ry2ev = EnergyConversion("rydberg", "eV").value()
kbar2evperang3 = PressureConversion("kbar", "eV/angstrom^3").value()

ABACUS_STRU_KEYS = [
"ATOMIC_SPECIES",
"NUMERICAL_ORBITAL",
"LATTICE_CONSTANT",
"LATTICE_VECTORS",
"ATOMIC_POSITIONS",
"NUMERICAL_DESCRIPTOR",
"PAW_FILES",
]


def CheckFile(ifile):
if not os.path.isfile(ifile):
Expand Down Expand Up @@ -43,6 +53,29 @@ def get_block(lines, keyword, skip=0, nlines=None):
return ret


def get_stru_block(lines, keyword):
# return the block of lines after keyword in STRU file, and skip the blank lines

def clean_comment(line):
return re.split("[#]", line)[0]

ret = []
found = False
for i in range(len(lines)):
if clean_comment(lines[i]).strip() == keyword:
found = True
for j in range(i + 1, len(lines)):
if clean_comment(lines[j]).strip() == "":
continue
elif clean_comment(lines[j]).strip() in ABACUS_STRU_KEYS:
break
else:
ret.append(clean_comment(lines[j]))
if not found:
return None
return ret


def get_geometry_in(fname, inlines):
geometry_path_in = os.path.join(fname, "STRU")
for line in inlines:
Expand All @@ -64,8 +97,8 @@ def get_path_out(fname, inlines):


def get_cell(geometry_inlines):
cell_lines = get_block(geometry_inlines, "LATTICE_VECTORS", skip=0, nlines=3)
celldm_lines = get_block(geometry_inlines, "LATTICE_CONSTANT", skip=0, nlines=1)
cell_lines = get_stru_block(geometry_inlines, "LATTICE_VECTORS")
celldm_lines = get_stru_block(geometry_inlines, "LATTICE_CONSTANT")

celldm = float(celldm_lines[0].split()[0]) * bohr2ang # lattice const is in Bohr
cell = []
Expand All @@ -76,7 +109,7 @@ def get_cell(geometry_inlines):


def get_coords(celldm, cell, geometry_inlines, inlines=None):
coords_lines = get_block(geometry_inlines, "ATOMIC_POSITIONS", skip=0)
coords_lines = get_stru_block(geometry_inlines, "ATOMIC_POSITIONS")
# assuming that ATOMIC_POSITIONS is at the bottom of the STRU file
coord_type = coords_lines[0].split()[0].lower() # cartisan or direct
atom_names = [] # element abbr in periodic table
Expand Down
1 change: 1 addition & 0 deletions dpdata/amber/mask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Amber mask."""

try:
import parmed
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions dpdata/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command line interface for dpdata."""

import argparse
from typing import Optional

Expand Down
4 changes: 1 addition & 3 deletions dpdata/cp2k/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def get_xyz_block_generator(self):
lines.append(self.xyz_file_object.readline())
if not lines[-1]:
raise RuntimeError(
"this xyz file may lack of lines, should be {};lines:{}".format(
atom_num + 2, lines
)
f"this xyz file may lack of lines, should be {atom_num + 2};lines:{lines}"
)
yield lines

Expand Down
1 change: 1 addition & 0 deletions dpdata/deepmd/hdf5.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utils for deepmd/hdf5 format."""

from __future__ import annotations

import warnings
Expand Down
3 changes: 3 additions & 0 deletions dpdata/driver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Driver plugin system."""

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Callable, List, Union

Expand Down Expand Up @@ -163,6 +164,8 @@ def label(self, data: dict) -> dict:
else:
labeled_data["energies"] += lb_data["energies"]
labeled_data["forces"] += lb_data["forces"]
if "virials" in labeled_data and "virials" in lb_data:
labeled_data["virials"] += lb_data["virials"]
return labeled_data


Expand Down
1 change: 1 addition & 0 deletions dpdata/format.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implement the format plugin system."""

import os
from abc import ABC

Expand Down
27 changes: 27 additions & 0 deletions dpdata/gaussian/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@


def to_system_data(file_name, md=False):
"""Read Gaussian log file.
Parameters
----------
file_name : str
file name
md : bool, default False
whether to read multiple frames
Returns
-------
data : dict
system data
Raises
------
RuntimeError
if the input orientation is not found
"""
data = {}
# read from log lines
flag = 0
Expand All @@ -20,6 +39,7 @@ def to_system_data(file_name, md=False):
forces_t = []
cells_t = []
nopbc = True
coords = None

with open(file_name) as fp:
for line in fp:
Expand All @@ -44,6 +64,12 @@ def to_system_data(file_name, md=False):
elif flag == 4:
# forces
if line.startswith(" -------"):
if coords is None:
raise RuntimeError(
"Input orientation is not found. Using Gaussian keyword "
"`Geom=PrintInputOrient` to always print the input orientation. "
"See https://gaussian.com/geom/ for more details."
)
forces_t.append(forces)
energy_t.append(energy)
coords_t.append(coords)
Expand All @@ -55,6 +81,7 @@ def to_system_data(file_name, md=False):
[[100.0, 0.0, 0.0], [0.0, 100.0, 0.0], [0.0, 0.0, 100.0]]
)
flag = 0
coords = None
else:
s = line.split()
if line[14:16] == "-2":
Expand Down
4 changes: 2 additions & 2 deletions dpdata/lammps/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def safe_get_posi(lines, cell, orig=np.zeros(3), unwrap=False):
category=UnwrapWarning,
)
return (
posis % 1
) @ cell # Convert scaled coordinates back to Cartesien coordinates with wraping at periodic boundary conditions
(posis % 1) @ cell
) # Convert scaled coordinates back to Cartesien coordinates with wraping at periodic boundary conditions


def get_dumpbox(lines):
Expand Down
Empty file added dpdata/openmx/__init__.py
Empty file.
Loading

0 comments on commit 658a511

Please sign in to comment.