Skip to content

Commit 6387419

Browse files
authored
v0.2.21 (#729)
2 parents c685e62 + c1d6c73 commit 6387419

Some content is hidden

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

42 files changed

+4238
-232
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
# Python
2222
- repo: https://github.com/astral-sh/ruff-pre-commit
2323
# Ruff version.
24-
rev: v0.6.3
24+
rev: v0.6.5
2525
hooks:
2626
- id: ruff
2727
args: ["--fix"]

docs/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Plugins
22

33
One can follow a simple example under `plugin_example/` directory to add their own format by creating and installing plugins.
4-
It's critical to add the :class:`Format` class to `entry_points['dpdata.plugins']` in `pyproject.toml`:
4+
It's critical to add the {class}`Format <dpdata.format.Format>` class to `entry_points['dpdata.plugins']` in `pyproject.toml`:
55

66
```toml
77
[project.entry-points.'dpdata.plugins']

docs/systems/bond_order_system.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
## BondOrderSystem
3-
A new class :class:`BondOrderSystem` which inherits from class :class:`System` is introduced in dpdata. This new class contains information of chemical bonds and formal charges (stored in `BondOrderSystem.data['bonds']`, `BondOrderSystem.data['formal_charges']`). Now BondOrderSystem can only read from .mol/.sdf formats, because of its dependency on rdkit (which means rdkit must be installed if you want to use this function). Other formats, such as pdb, must be converted to .mol/.sdf format (maybe with software like open babel).
3+
A new class {class}`BondOrderSystem <dpdata.BondOrderSystem>` which inherits from class {class}`System <dpdata.System>` is introduced in dpdata. This new class contains information of chemical bonds and formal charges (stored in `BondOrderSystem.data['bonds']`, `BondOrderSystem.data['formal_charges']`). Now BondOrderSystem can only read from .mol/.sdf formats, because of its dependency on rdkit (which means rdkit must be installed if you want to use this function). Other formats, such as pdb, must be converted to .mol/.sdf format (maybe with software like open babel).
44
```python
55
import dpdata
66

@@ -12,7 +12,7 @@ system_2 = dpdata.BondOrderSystem(
1212
) # read from .sdf file
1313
```
1414
In sdf file, all molecules must be of the same topology (i.e. conformers of the same molecular configuration).
15-
`BondOrderSystem` also supports initialize from a :class:`rdkit.Chem.rdchem.Mol` object directly.
15+
`BondOrderSystem <dpdata.BondOrderSystem>` also supports initialize from a {class}`rdkit.Chem.rdchem.Mol` object directly.
1616
```python
1717
from rdkit import Chem
1818
from rdkit.Chem import AllChem
@@ -25,7 +25,7 @@ system = dpdata.BondOrderSystem(rdkit_mol=mol)
2525
```
2626

2727
### Bond Order Assignment
28-
The :class:`BondOrderSystem` implements a more robust sanitize procedure for rdkit Mol, as defined in :class:`dpdata.rdkit.santizie.Sanitizer`. This class defines 3 level of sanitization process by: low, medium and high. (default is medium).
28+
The {class}`BondOrderSystem <dpdata.BondOrderSystem>` implements a more robust sanitize procedure for rdkit Mol, as defined in {class}`dpdata.rdkit.santizie.Sanitizer`. This class defines 3 level of sanitization process by: low, medium and high. (default is medium).
2929
+ low: use `rdkit.Chem.SanitizeMol()` function to sanitize molecule.
3030
+ medium: before using rdkit, the programm will first assign formal charge of each atom to avoid inappropriate valence exceptions. However, this mode requires the rightness of the bond order information in the given molecule.
3131
+ high: the program will try to fix inappropriate bond orders in aromatic hetreocycles, phosphate, sulfate, carboxyl, nitro, nitrine, guanidine groups. If this procedure fails to sanitize the given molecule, the program will then try to call `obabel` to pre-process the mol and repeat the sanitization procedure. **That is to say, if you wan't to use this level of sanitization, please ensure `obabel` is installed in the environment.**

docs/systems/mixed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Mixed Type Format
22

3-
The format `deepmd/npy/mixed` is the mixed type numpy format for DeePMD-kit, and can be loaded or dumped through class :class:`dpdata.MultiSystems`.
3+
The format `deepmd/npy/mixed` is the mixed type numpy format for DeePMD-kit, and can be loaded or dumped through class {class}`dpdata.MultiSystems`.
44

55
Under this format, systems with the same number of atoms but different formula can be put together
66
for a larger system, especially when the frame numbers in systems are sparse.

docs/systems/multi.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# `MultiSystems`
22

3-
The Class :class:`dpdata.MultiSystems` can read data from a dir which may contains many files of different systems, or from single xyz file which contains different systems.
3+
The Class {class}`dpdata.MultiSystems` can read data from a dir which may contains many files of different systems, or from single xyz file which contains different systems.
44

5-
Use :meth:`dpdata.MultiSystems.from_dir` to read from a directory, :class:`dpdata.MultiSystems` will walk in the directory
6-
Recursively and find all file with specific file_name. Supports all the file formats that :class:`dpdata.LabeledSystem` supports.
5+
Use {meth}`dpdata.MultiSystems.from_dir` to read from a directory, {class}`dpdata.MultiSystems` will walk in the directory
6+
Recursively and find all file with specific file_name. Supports all the file formats that {class}`dpdata.LabeledSystem` supports.
77

8-
Use :meth:`dpdata.MultiSystems.from_file` to read from single file. Single-file support is available for the `quip/gap/xyz` and `ase/structure` formats.
8+
Use {meth}`dpdata.MultiSystems.from_file` to read from single file. Single-file support is available for the `quip/gap/xyz` and `ase/structure` formats.
99

1010
For example, for `quip/gap xyz` files, single .xyz file may contain many different configurations with different atom numbers and atom type.
1111

12-
The following commands relating to :class:`dpdata.MultiSystems` may be useful.
12+
The following commands relating to {class}`dpdata.MultiSystems` may be useful.
1313
```python
1414
# load data
1515

docs/systems/system.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ or let dpdata infer the format (`vasp/poscar`) of the file from the file name ex
1919
```python
2020
d_poscar = dpdata.System("my.POSCAR")
2121
```
22-
The number of atoms, atom types, coordinates are loaded from the `POSCAR` and stored to a data :class:`System` called `d_poscar`.
23-
A data :class:`System` (a concept used by [deepmd-kit](https://github.com/deepmodeling/deepmd-kit)) contains frames that has the same number of atoms of the same type. The order of the atoms should be consistent among the frames in one :class:`System`.
22+
The number of atoms, atom types, coordinates are loaded from the `POSCAR` and stored to a data {class}`System <dpdata.System>` called `d_poscar`.
23+
A data {class}`System <dpdata.System>` (a concept used by [deepmd-kit](https://github.com/deepmodeling/deepmd-kit)) contains frames that has the same number of atoms of the same type. The order of the atoms should be consistent among the frames in one {class}`System <dpdata.System>`.
2424
It is noted that `POSCAR` only contains one frame.
2525
If the multiple frames stored in, for example, a `OUTCAR` is wanted,
2626
```python
2727
d_outcar = dpdata.LabeledSystem("OUTCAR")
2828
```
29-
The labels provided in the `OUTCAR`, i.e. energies, forces and virials (if any), are loaded by :class:`LabeledSystem`. It is noted that the forces of atoms are always assumed to exist. :class:`LabeledSystem` is a derived class of :class:`System`.
29+
The labels provided in the `OUTCAR`, i.e. energies, forces and virials (if any), are loaded by {class}`LabeledSystem <dpdata.LabeledSystem>`. It is noted that the forces of atoms are always assumed to exist. {class}`LabeledSystem <dpdata.LabeledSystem>` is a derived class of {class}`System <dpdata.System>`.
3030

31-
The :class:`System` or :class:`LabeledSystem` can be constructed from the following file formats with the `format key` in the table passed to argument `fmt`:
31+
The {class}`System <dpdata.System>` or {class}`LabeledSystem <dpdata.LabeledSystem>` can be constructed from the [supported file formats](../formats.rst) with the `format key` in the table passed to argument `fmt`.
3232

3333

3434

3535
### Access data
36-
These properties stored in :class:`System` and :class:`LabeledSystem` can be accessed by operator `[]` with the key of the property supplied, for example
36+
These properties stored in {class}`System <dpdata.System>` and {class}`LabeledSystem <dpdata.LabeledSystem>` can be accessed by operator `[]` with the key of the property supplied, for example
3737
```python
3838
coords = d_outcar["coords"]
3939
```
@@ -52,7 +52,7 @@ Available properties are (nframe: number of frames in the system, natoms: total
5252

5353

5454
### Dump data
55-
The data stored in :class:`System` or :class:`LabeledSystem` can be dumped in 'lammps/lmp' or 'vasp/poscar' format, for example:
55+
The data stored in {class}`System <dpdata.System>` or {class}`LabeledSystem <dpdata.LabeledSystem>` can be dumped in 'lammps/lmp' or 'vasp/poscar' format, for example:
5656
```python
5757
d_outcar.to("lammps/lmp", "conf.lmp", frame_idx=0)
5858
```

dpdata/abacus/md.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
get_cell,
1313
get_coords,
1414
get_geometry_in,
15+
get_mag_force,
1516
kbar2evperang3,
1617
)
1718

@@ -199,6 +200,9 @@ def get_frame(fname):
199200
stress[iframe] *= np.linalg.det(cells[iframe, :, :].reshape([3, 3]))
200201
if np.sum(np.abs(stress[0])) < 1e-10:
201202
stress = None
203+
204+
magmom, magforce = get_mag_force(outlines)
205+
202206
data = {}
203207
data["atom_names"] = atom_names
204208
data["atom_numbs"] = natoms
@@ -213,5 +217,9 @@ def get_frame(fname):
213217
if not isinstance(data["virials"], np.ndarray):
214218
del data["virials"]
215219
data["orig"] = np.zeros(3)
220+
if len(magmom) > 0:
221+
data["spins"] = magmom
222+
if len(magforce) > 0:
223+
data["mag_forces"] = magforce
216224

217225
return data

dpdata/abacus/relax.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
get_cell,
1414
get_coords,
1515
get_geometry_in,
16+
get_mag_force,
1617
kbar2evperang3,
1718
)
1819

@@ -198,6 +199,8 @@ def get_frame(fname):
198199
lines, atomnumber
199200
)
200201

202+
magmom, magforce = get_mag_force(lines)
203+
201204
data = {}
202205
data["atom_names"] = atom_names
203206
data["atom_numbs"] = natoms
@@ -211,4 +214,9 @@ def get_frame(fname):
211214
data["stress"] = stress
212215
data["orig"] = np.zeros(3)
213216

217+
if len(magmom) > 0:
218+
data["spins"] = magmom
219+
if len(magforce) > 0:
220+
data["mag_forces"] = magforce
221+
214222
return data

0 commit comments

Comments
 (0)