Skip to content

Commit 85a3b5e

Browse files
authored
Merge devel into master (#464)
2 parents 9507165 + b73b239 commit 85a3b5e

File tree

155 files changed

+7087
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+7087
-555
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ repos:
1818
- id: check-toml
1919
# Python
2020
- repo: https://github.com/psf/black
21-
rev: 22.12.0
21+
rev: 23.3.0
2222
hooks:
2323
- id: black-jupyter
24-
- repo: https://github.com/PyCQA/isort
25-
rev: 5.12.0
24+
- repo: https://github.com/charliermarsh/ruff-pre-commit
25+
# Ruff version.
26+
rev: v0.0.263
2627
hooks:
27-
- id: isort
28-
files: \.py$
28+
- id: ruff
29+
args: ["--fix"]
2930
# numpydoc
3031
- repo: https://github.com/Carreau/velin
3132
rev: 0.0.12

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Configuration file for the Sphinx documentation builder.
43
#

docs/make_format.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import csv
22
from collections import defaultdict
3-
from typing import Any
43

54
# ensure all plugins are loaded!
6-
import dpdata.plugins
75
from dpdata.driver import Driver, Minimizer
86
from dpdata.format import Format
9-
from dpdata.system import get_cls_name
107

118

129
def get_formats() -> dict:
@@ -31,7 +28,7 @@ def get_minimizer() -> dict:
3128

3229

3330
def detect_overridden(cls: Format, method: str) -> bool:
34-
"""Check whether a method is override
31+
"""Check whether a method is override.
3532
3633
Parameters
3734
----------
@@ -61,7 +58,9 @@ def get_cls_link(cls: object) -> str:
6158
str
6259
the link of a class
6360
"""
64-
return ":class:`%s <%s>`" % (cls.__name__, ".".join([cls.__module__, cls.__name__]))
61+
return ":class:`{} <{}>`".format(
62+
cls.__name__, ".".join([cls.__module__, cls.__name__])
63+
)
6564

6665

6766
def check_supported(fmt: Format):
@@ -112,7 +111,7 @@ def check_supported(fmt: Format):
112111
writer.writerow(
113112
{
114113
"Class": get_cls_link(kk),
115-
"Alias": "\n".join(("``%s``" % vvv for vvv in vv)),
114+
"Alias": "\n".join("``%s``" % vvv for vvv in vv),
116115
"Supported Functions": "\n".join(
117116
method_links[mtd] for mtd in check_supported(kk)
118117
),
@@ -132,7 +131,7 @@ def check_supported(fmt: Format):
132131
writer.writerow(
133132
{
134133
"Class": get_cls_link(kk),
135-
"Alias": "\n".join(("``%s``" % vvv for vvv in vv)),
134+
"Alias": "\n".join("``%s``" % vvv for vvv in vv),
136135
}
137136
)
138137

@@ -149,6 +148,6 @@ def check_supported(fmt: Format):
149148
writer.writerow(
150149
{
151150
"Class": get_cls_link(kk),
152-
"Alias": "\n".join(("``%s``" % vvv for vvv in vv)),
151+
"Alias": "\n".join("``%s``" % vvv for vvv in vv),
153152
}
154153
)

dpdata/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,22 @@
99
# BondOrder System has dependency on rdkit
1010
try:
1111
# prevent conflict with dpdata.rdkit
12-
import rdkit as _
12+
import rdkit as _ # noqa: F401
1313

1414
USE_RDKIT = True
1515
except ModuleNotFoundError:
1616
USE_RDKIT = False
1717

1818
if USE_RDKIT:
1919
from .bond_order_system import BondOrderSystem
20+
21+
__all__ = [
22+
"__version__",
23+
"lammps",
24+
"md",
25+
"vasp",
26+
"System",
27+
"LabeledSystem",
28+
"MultiSystems",
29+
"BondOrderSystem",
30+
]

dpdata/abacus/md.py

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import os
2-
import re
3-
import sys
42
import warnings
5-
from ast import dump
63

74
import numpy as np
85

96
from .scf import (
107
bohr2ang,
11-
get_block,
128
get_cell,
139
get_coords,
1410
get_geometry_in,
1511
kbar2evperang3,
16-
ry2ev,
1712
)
1813

1914
# Read in geometries from an ABACUS MD trajectory.
@@ -72,69 +67,51 @@ def get_coords_from_dump(dumplines, natoms):
7267
for iline in range(nlines):
7368
if "MDSTEP" in dumplines[iline]:
7469
# read in LATTICE_CONSTANT
75-
celldm = float(dumplines[iline + 1].split(" ")[-1])
70+
# for abacus version >= v3.1.4, the unit is angstrom, and "ANGSTROM" is added at the end
71+
# for abacus version < v3.1.4, the unit is bohr
72+
celldm = float(dumplines[iline + 1].split()[1])
73+
newversion = True
74+
if "Angstrom" not in dumplines[iline + 1]:
75+
celldm *= bohr2ang # transfer unit to ANGSTROM
76+
newversion = False
77+
7678
# read in LATTICE_VECTORS
7779
for ix in range(3):
7880
cells[iframe, ix] = (
79-
np.array(
80-
[
81-
float(i)
82-
for i in re.split("\s+", dumplines[iline + 3 + ix])[-3:]
83-
]
84-
)
81+
np.array([float(i) for i in dumplines[iline + 3 + ix].split()[0:3]])
8582
* celldm
8683
)
8784
if calc_stress:
8885
stresses[iframe, ix] = np.array(
89-
[
90-
float(i)
91-
for i in re.split("\s+", dumplines[iline + 7 + ix])[-3:]
92-
]
86+
[float(i) for i in dumplines[iline + 7 + ix].split()[0:3]]
9387
)
88+
89+
if calc_stress:
90+
skipline = 11
91+
else:
92+
skipline = 7
93+
9494
for iat in range(total_natoms):
95-
if calc_stress:
96-
coords[iframe, iat] = (
97-
np.array(
98-
[
99-
float(i)
100-
for i in re.split("\s+", dumplines[iline + 11 + iat])[
101-
-6:-3
102-
]
103-
]
104-
)
105-
* celldm
106-
)
107-
forces[iframe, iat] = np.array(
108-
[
109-
float(i)
110-
for i in re.split("\s+", dumplines[iline + 11 + iat])[-3:]
111-
]
112-
)
113-
else:
114-
coords[iframe, iat] = (
115-
np.array(
116-
[
117-
float(i)
118-
for i in re.split("\s+", dumplines[iline + 7 + iat])[
119-
-6:-3
120-
]
121-
]
122-
)
123-
* celldm
124-
)
125-
forces[iframe, iat] = np.array(
126-
[
127-
float(i)
128-
for i in re.split("\s+", dumplines[iline + 7 + iat])[-3:]
129-
]
130-
)
95+
# INDEX LABEL POSITION (Angstrom) FORCE (eV/Angstrom) VELOCITY (Angstrom/fs)
96+
# 0 Sn 0.000000000000 0.000000000000 0.000000000000 -0.000000000000 -0.000000000001 -0.000000000001 0.001244557166 -0.000346684288 0.000768457739
97+
# 1 Sn 0.000000000000 3.102800034079 3.102800034079 -0.000186795145 -0.000453823768 -0.000453823768 0.000550996187 -0.000886442775 0.001579501983
98+
# for abacus version >= v3.1.4, the value of POSITION is the real cartessian position, and unit is angstrom, and if cal_force the VELOCITY is added at the end.
99+
# for abacus version < v3.1.4, the real position = POSITION * celldm
100+
coords[iframe, iat] = np.array(
101+
[float(i) for i in dumplines[iline + skipline + iat].split()[2:5]]
102+
)
103+
104+
if not newversion:
105+
coords[iframe, iat] *= celldm
106+
107+
forces[iframe, iat] = np.array(
108+
[float(i) for i in dumplines[iline + skipline + iat].split()[5:8]]
109+
)
131110
iframe += 1
132111
assert iframe == nframes_dump, (
133112
"iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump."
134113
% (iframe, nframes_dump)
135114
)
136-
cells *= bohr2ang
137-
coords *= bohr2ang
138115
stresses *= kbar2evperang3
139116
return coords, cells, forces, stresses
140117

@@ -166,12 +143,12 @@ def get_frame(fname):
166143
path_in = os.path.join(fname, "INPUT")
167144
else:
168145
raise RuntimeError("invalid input")
169-
with open(path_in, "r") as fp:
146+
with open(path_in) as fp:
170147
inlines = fp.read().split("\n")
171148
geometry_path_in = get_geometry_in(fname, inlines) # base dir of STRU
172149
path_out = get_path_out(fname, inlines)
173150

174-
with open(geometry_path_in, "r") as fp:
151+
with open(geometry_path_in) as fp:
175152
geometry_inlines = fp.read().split("\n")
176153
celldm, cell = get_cell(geometry_inlines)
177154
atom_names, natoms, types, coords = get_coords(
@@ -182,11 +159,11 @@ def get_frame(fname):
182159
# ndump = int(os.popen("ls -l %s | grep 'md_pos_' | wc -l" %path_out).readlines()[0])
183160
# number of dumped geometry files
184161
# coords = get_coords_from_cif(ndump, dump_freq, atom_names, natoms, types, path_out, cell)
185-
with open(os.path.join(path_out, "MD_dump"), "r") as fp:
162+
with open(os.path.join(path_out, "MD_dump")) as fp:
186163
dumplines = fp.read().split("\n")
187164
coords, cells, force, stress = get_coords_from_dump(dumplines, natoms)
188165
ndump = np.shape(coords)[0]
189-
with open(os.path.join(path_out, "running_md.log"), "r") as fp:
166+
with open(os.path.join(path_out, "running_md.log")) as fp:
190167
outlines = fp.read().split("\n")
191168
energy = get_energy(outlines, ndump, dump_freq)
192169

@@ -201,7 +178,7 @@ def get_frame(fname):
201178
unconv_stru += "%d " % i
202179
ndump = len(energy)
203180
if unconv_stru != "":
204-
warnings.warn(f"Structure %s are unconverged and not collected!" % unconv_stru)
181+
warnings.warn("Structure %s are unconverged and not collected!" % unconv_stru)
205182

206183
for iframe in range(ndump):
207184
stress[iframe] *= np.linalg.det(cells[iframe, :, :].reshape([3, 3]))

dpdata/abacus/relax.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import sys
32

43
import numpy as np
54

@@ -16,19 +15,18 @@ def get_log_file(fname, inlines):
1615
suffix = line.split()[1]
1716
elif "calculation" in line and "calculation" == line.split()[0]:
1817
calculation = line.split()[1]
19-
logf = os.path.join(fname, "OUT.%s/running_%s.log" % (suffix, calculation))
18+
logf = os.path.join(fname, f"OUT.{suffix}/running_{calculation}.log")
2019
return logf
2120

2221

2322
def get_coords_from_log(loglines, natoms):
24-
"""
25-
NOTICE: unit of coords and cells is Angstrom
23+
"""NOTICE: unit of coords and cells is Angstrom
2624
order:
2725
coordinate
2826
cell (no output if cell is not changed)
2927
energy (no output, if SCF is not converged)
3028
force (no output, if cal_force is not setted or abnormal ending)
31-
stress (no output, if set cal_stress is not setted or abnormal ending)
29+
stress (no output, if set cal_stress is not setted or abnormal ending).
3230
"""
3331
natoms_log = 0
3432
for line in loglines:
@@ -175,10 +173,10 @@ def get_frame(fname):
175173
path_in = os.path.join(fname, "INPUT")
176174
else:
177175
raise RuntimeError("invalid input")
178-
with open(path_in, "r") as fp:
176+
with open(path_in) as fp:
179177
inlines = fp.read().split("\n")
180178
geometry_path_in = get_geometry_in(fname, inlines) # base dir of STRU
181-
with open(geometry_path_in, "r") as fp:
179+
with open(geometry_path_in) as fp:
182180
geometry_inlines = fp.read().split("\n")
183181
celldm, cell = get_cell(geometry_inlines)
184182
atom_names, natoms, types, coord_tmp = get_coords(

dpdata/abacus/scf.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import re
3-
import sys
43

54
import numpy as np
65

@@ -172,17 +171,17 @@ def get_frame(fname):
172171
if not CheckFile(path_in):
173172
return data
174173

175-
with open(path_in, "r") as fp:
174+
with open(path_in) as fp:
176175
inlines = fp.read().split("\n")
177176

178177
geometry_path_in = get_geometry_in(fname, inlines)
179178
path_out = get_path_out(fname, inlines)
180179
if not (CheckFile(geometry_path_in) and CheckFile(path_out)):
181180
return data
182181

183-
with open(geometry_path_in, "r") as fp:
182+
with open(geometry_path_in) as fp:
184183
geometry_inlines = fp.read().split("\n")
185-
with open(path_out, "r") as fp:
184+
with open(path_out) as fp:
186185
outlines = fp.read().split("\n")
187186

188187
celldm, cell = get_cell(geometry_inlines)
@@ -257,7 +256,7 @@ def get_nele_from_stru(geometry_inlines):
257256

258257
def get_frame_from_stru(fname):
259258
assert type(fname) == str
260-
with open(fname, "r") as fp:
259+
with open(fname) as fp:
261260
geometry_inlines = fp.read().split("\n")
262261
nele = get_nele_from_stru(geometry_inlines)
263262
inlines = ["ntype %d" % nele]

dpdata/amber/mask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
"""Amber mask"""
1+
"""Amber mask."""
22
try:
33
import parmed
44
except ImportError:
55
pass
66

77

88
def pick_by_amber_mask(param, maskstr, coords=None):
9-
"""Pick atoms by amber masks
9+
"""Pick atoms by amber masks.
1010
1111
Parameters
1212
----------

dpdata/amber/md.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def read_amber_traj(
3030
* mdfrc, NetCDF format, stores forces
3131
* mden (optional), text format, stores energies
3232
* mdout (optional), text format, may store energies if there is no mden_file
33-
* parm7, text format, stores types
33+
* parm7, text format, stores types.
3434
3535
Parameters
3636
----------
@@ -41,8 +41,9 @@ def read_amber_traj(
4141
instead of amber types. For example, a ligand will use C, H, O, N, and so on
4242
instead of h1, hc, o, os, and so on.
4343
IF use_element_symbols is str, it will be considered as Amber mask.
44+
labeled : bool
45+
Whether to return labeled data
4446
"""
45-
4647
flag_atom_type = False
4748
flag_atom_numb = False
4849
amber_types = []

dpdata/amber/sqm.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414

1515
def parse_sqm_out(fname):
16-
"""
17-
Read atom symbols, charges and coordinates from ambertools sqm.out file
18-
"""
16+
"""Read atom symbols, charges and coordinates from ambertools sqm.out file."""
1917
atom_symbols = []
2018
coords = []
2119
charges = []

0 commit comments

Comments
 (0)