Skip to content

Commit

Permalink
v0.2.21 (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz authored Sep 20, 2024
2 parents c685e62 + c1d6c73 commit 6387419
Show file tree
Hide file tree
Showing 42 changed files with 4,238 additions and 232 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.3
rev: v0.6.5
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 1 addition & 1 deletion docs/plugin.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Plugins

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

```toml
[project.entry-points.'dpdata.plugins']
Expand Down
6 changes: 3 additions & 3 deletions docs/systems/bond_order_system.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

## BondOrderSystem
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).
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).
```python
import dpdata

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

### Bond Order Assignment
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).
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).
+ low: use `rdkit.Chem.SanitizeMol()` function to sanitize molecule.
+ 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.
+ 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.**
Expand Down
2 changes: 1 addition & 1 deletion docs/systems/mixed.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mixed Type Format

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`.
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`.

Under this format, systems with the same number of atoms but different formula can be put together
for a larger system, especially when the frame numbers in systems are sparse.
Expand Down
10 changes: 5 additions & 5 deletions docs/systems/multi.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# `MultiSystems`

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.
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.

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

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.
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.

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

The following commands relating to :class:`dpdata.MultiSystems` may be useful.
The following commands relating to {class}`dpdata.MultiSystems` may be useful.
```python
# load data

Expand Down
12 changes: 6 additions & 6 deletions docs/systems/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ or let dpdata infer the format (`vasp/poscar`) of the file from the file name ex
```python
d_poscar = dpdata.System("my.POSCAR")
```
The number of atoms, atom types, coordinates are loaded from the `POSCAR` and stored to a data :class:`System` called `d_poscar`.
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`.
The number of atoms, atom types, coordinates are loaded from the `POSCAR` and stored to a data {class}`System <dpdata.System>` called `d_poscar`.
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>`.
It is noted that `POSCAR` only contains one frame.
If the multiple frames stored in, for example, a `OUTCAR` is wanted,
```python
d_outcar = dpdata.LabeledSystem("OUTCAR")
```
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`.
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>`.

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`:
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`.



### Access data
These properties stored in :class:`System` and :class:`LabeledSystem` can be accessed by operator `[]` with the key of the property supplied, for example
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
```python
coords = d_outcar["coords"]
```
Expand All @@ -52,7 +52,7 @@ Available properties are (nframe: number of frames in the system, natoms: total


### Dump data
The data stored in :class:`System` or :class:`LabeledSystem` can be dumped in 'lammps/lmp' or 'vasp/poscar' format, for example:
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:
```python
d_outcar.to("lammps/lmp", "conf.lmp", frame_idx=0)
```
Expand Down
8 changes: 8 additions & 0 deletions dpdata/abacus/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_cell,
get_coords,
get_geometry_in,
get_mag_force,
kbar2evperang3,
)

Expand Down Expand Up @@ -199,6 +200,9 @@ def get_frame(fname):
stress[iframe] *= np.linalg.det(cells[iframe, :, :].reshape([3, 3]))
if np.sum(np.abs(stress[0])) < 1e-10:
stress = None

magmom, magforce = get_mag_force(outlines)

data = {}
data["atom_names"] = atom_names
data["atom_numbs"] = natoms
Expand All @@ -213,5 +217,9 @@ def get_frame(fname):
if not isinstance(data["virials"], np.ndarray):
del data["virials"]
data["orig"] = np.zeros(3)
if len(magmom) > 0:
data["spins"] = magmom
if len(magforce) > 0:
data["mag_forces"] = magforce

return data
8 changes: 8 additions & 0 deletions dpdata/abacus/relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
get_cell,
get_coords,
get_geometry_in,
get_mag_force,
kbar2evperang3,
)

Expand Down Expand Up @@ -198,6 +199,8 @@ def get_frame(fname):
lines, atomnumber
)

magmom, magforce = get_mag_force(lines)

data = {}
data["atom_names"] = atom_names
data["atom_numbs"] = natoms
Expand All @@ -211,4 +214,9 @@ def get_frame(fname):
data["stress"] = stress
data["orig"] = np.zeros(3)

if len(magmom) > 0:
data["spins"] = magmom
if len(magforce) > 0:
data["mag_forces"] = magforce

return data
Loading

0 comments on commit 6387419

Please sign in to comment.