Skip to content

Commit f4d0adf

Browse files
authored
docs: reformat README and documentation (#707)
Move most of the contents from `README.md` to `docs`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced `BondOrderSystem` class for managing chemical bonds and formal charges. - Added `MultiSystems` class for handling multiple system data from files or directories. - Implemented new `deepmd/npy/mixed` format for combining systems with different formulas. - Launched plugin documentation to enhance extensibility for user-created plugins. - **Documentation** - Updated README for clearer installation instructions and streamlined content. - Created dedicated installation guide for user-friendly setup. - Enhanced documentation structure with new entries and improved navigation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent 35fdbb8 commit f4d0adf

File tree

9 files changed

+312
-302
lines changed

9 files changed

+312
-302
lines changed

README.md

Lines changed: 25 additions & 298 deletions
Large diffs are not rendered by default.

docs/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
Welcome to dpdata's documentation!
77
==================================
88

9+
dpdata is a Python package for manipulating atomistic data of software in computational science.
10+
911
.. toctree::
1012
:maxdepth: 2
1113
:caption: Contents:
1214

13-
Overview <self>
15+
installation
16+
systems/index
1417
try_dpdata
1518
cli
1619
formats
1720
drivers
1821
minimizers
22+
plugin
1923
api/api
2024
credits
2125

22-
.. mdinclude:: ../README.md
23-
24-
2526
Indices and tables
2627
==================
2728

docs/installation.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Installation
2+
3+
DP-GEN only supports Python 3.7 and above. You can [setup a conda/pip environment](https://docs.deepmodeling.com/faq/conda.html), and then use one of the following methods to install DP-GEN:
4+
5+
- Install via pip: `pip install dpdata`
6+
- Install via conda: `conda install -c conda-forge dpdata`
7+
- Install from source code: `git clone https://github.com/deepmodeling/dpdata && pip install ./dpdata`
8+
9+
To test if the installation is successful, you may execute
10+
11+
```bash
12+
dpdata --version
13+
```

docs/plugin.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Plugins
2+
3+
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`:
5+
6+
```toml
7+
[project.entry-points.'dpdata.plugins']
8+
random = "dpdata_random:RandomFormat"
9+
```

docs/systems/bond_order_system.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
## 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).
4+
```python
5+
import dpdata
6+
7+
system_1 = dpdata.BondOrderSystem(
8+
"tests/bond_order/CH3OH.mol", fmt="mol"
9+
) # read from .mol file
10+
system_2 = dpdata.BondOrderSystem(
11+
"tests/bond_order/methane.sdf", fmt="sdf"
12+
) # read from .sdf file
13+
```
14+
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.
16+
```python
17+
from rdkit import Chem
18+
from rdkit.Chem import AllChem
19+
import dpdata
20+
21+
mol = Chem.MolFromSmiles("CC")
22+
mol = Chem.AddHs(mol)
23+
AllChem.EmbedMultipleConfs(mol, 10)
24+
system = dpdata.BondOrderSystem(rdkit_mol=mol)
25+
```
26+
27+
### 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).
29+
+ low: use `rdkit.Chem.SanitizeMol()` function to sanitize molecule.
30+
+ 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.
31+
+ 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.**
32+
According to our test, our sanitization procedure can successfully read 4852 small molecules in the PDBBind-refined-set. It is necessary to point out that the in the molecule file (mol/sdf), the number of explicit hydrogens has to be correct. Thus, we recommend to use
33+
`obabel xxx -O xxx -h` to pre-process the file. The reason why we do not implement this hydrogen-adding procedure in dpdata is that we can not ensure its correctness.
34+
35+
```python
36+
import dpdata
37+
38+
for sdf_file in glob.glob("bond_order/refined-set-ligands/obabel/*sdf"):
39+
syst = dpdata.BondOrderSystem(sdf_file, sanitize_level="high", verbose=False)
40+
```
41+
### Formal Charge Assignment
42+
BondOrderSystem implement a method to assign formal charge for each atom based on the 8-electron rule (see below). Note that it only supports common elements in bio-system: B,C,N,O,P,S,As
43+
```python
44+
import dpdata
45+
46+
syst = dpdata.BondOrderSystem("tests/bond_order/CH3NH3+.mol", fmt="mol")
47+
print(syst.get_formal_charges()) # return the formal charge on each atom
48+
print(syst.get_charge()) # return the total charge of the system
49+
```
50+
51+
If a valence of 3 is detected on carbon, the formal charge will be assigned to -1. Because for most cases (in alkynyl anion, isonitrile, cyclopentadienyl anion), the formal charge on 3-valence carbon is -1, and this is also consisent with the 8-electron rule.

docs/systems/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Systems
2+
=======
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
:caption: Contents:
7+
8+
system
9+
multi
10+
bond_order_system
11+
mixed

docs/systems/mixed.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Mixed Type Format
2+
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`.
4+
5+
Under this format, systems with the same number of atoms but different formula can be put together
6+
for a larger system, especially when the frame numbers in systems are sparse.
7+
8+
This also helps to mixture the type information together for model training with type embedding network.
9+
10+
Here are examples using `deepmd/npy/mixed` format:
11+
12+
- Dump a MultiSystems into a mixed type numpy directory:
13+
```python
14+
import dpdata
15+
16+
dpdata.MultiSystems(*systems).to_deepmd_npy_mixed("mixed_dir")
17+
```
18+
19+
- Load a mixed type data into a MultiSystems:
20+
```python
21+
import dpdata
22+
23+
dpdata.MultiSystems().load_systems_from_file("mixed_dir", fmt="deepmd/npy/mixed")
24+
```

docs/systems/multi.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# `MultiSystems`
2+
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.
4+
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.
7+
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.
9+
10+
For example, for `quip/gap xyz` files, single .xyz file may contain many different configurations with different atom numbers and atom type.
11+
12+
The following commands relating to :class:`dpdata.MultiSystems` may be useful.
13+
```python
14+
# load data
15+
16+
xyz_multi_systems = dpdata.MultiSystems.from_file(
17+
file_name="tests/xyz/xyz_unittest.xyz", fmt="quip/gap/xyz"
18+
)
19+
vasp_multi_systems = dpdata.MultiSystems.from_dir(
20+
dir_name="./mgal_outcar", file_name="OUTCAR", fmt="vasp/outcar"
21+
)
22+
23+
# use wildcard
24+
vasp_multi_systems = dpdata.MultiSystems.from_dir(
25+
dir_name="./mgal_outcar", file_name="*OUTCAR", fmt="vasp/outcar"
26+
)
27+
28+
# print the multi_system infomation
29+
print(xyz_multi_systems)
30+
print(xyz_multi_systems.systems) # return a dictionaries
31+
32+
# print the system infomation
33+
print(xyz_multi_systems.systems["B1C9"].data)
34+
35+
# dump a system's data to ./my_work_dir/B1C9_raw folder
36+
xyz_multi_systems.systems["B1C9"].to_deepmd_raw("./my_work_dir/B1C9_raw")
37+
38+
# dump all systems
39+
xyz_multi_systems.to_deepmd_raw("./my_deepmd_data/")
40+
```
41+
42+
You may also use the following code to parse muti-system:
43+
```python
44+
from dpdata import LabeledSystem, MultiSystems
45+
from glob import glob
46+
47+
"""
48+
process multi systems
49+
"""
50+
fs = glob("./*/OUTCAR") # remeber to change here !!!
51+
ms = MultiSystems()
52+
for f in fs:
53+
try:
54+
ls = LabeledSystem(f)
55+
except:
56+
print(f)
57+
if len(ls) > 0:
58+
ms.append(ls)
59+
60+
ms.to_deepmd_raw("deepmd")
61+
ms.to_deepmd_npy("deepmd")
62+
```

docs/systems/system.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# `System` and `LabeledSystem`
2+
3+
This section gives some examples on how dpdata works. Firstly one needs to import the module in a python 3.x compatible code.
4+
```python
5+
import dpdata
6+
```
7+
The typicall workflow of `dpdata` is
8+
9+
1. Load data from vasp or lammps or deepmd-kit data files.
10+
2. Manipulate data
11+
3. Dump data to in a desired format
12+
13+
14+
### Load data
15+
```python
16+
d_poscar = dpdata.System("POSCAR", fmt="vasp/poscar")
17+
```
18+
or let dpdata infer the format (`vasp/poscar`) of the file from the file name extension
19+
```python
20+
d_poscar = dpdata.System("my.POSCAR")
21+
```
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`.
24+
It is noted that `POSCAR` only contains one frame.
25+
If the multiple frames stored in, for example, a `OUTCAR` is wanted,
26+
```python
27+
d_outcar = dpdata.LabeledSystem("OUTCAR")
28+
```
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`.
30+
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`:
32+
33+
34+
35+
### 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
37+
```python
38+
coords = d_outcar["coords"]
39+
```
40+
Available properties are (nframe: number of frames in the system, natoms: total number of atoms in the system)
41+
42+
| key | type | dimension | are labels | description
43+
| --- | --- | --- | --- | ---
44+
| 'atom_names' | list of str | ntypes | False | The name of each atom type
45+
| 'atom_numbs' | list of int | ntypes | False | The number of atoms of each atom type
46+
| 'atom_types' | np.ndarray | natoms | False | Array assigning type to each atom
47+
| 'cells' | np.ndarray | nframes x 3 x 3 | False | The cell tensor of each frame
48+
| 'coords' | np.ndarray | nframes x natoms x 3 | False | The atom coordinates
49+
| 'energies' | np.ndarray | nframes | True | The frame energies
50+
| 'forces' | np.ndarray | nframes x natoms x 3 | True | The atom forces
51+
| 'virials' | np.ndarray | nframes x 3 x 3 | True | The virial tensor of each frame
52+
53+
54+
### Dump data
55+
The data stored in :class:`System` or :class:`LabeledSystem` can be dumped in 'lammps/lmp' or 'vasp/poscar' format, for example:
56+
```python
57+
d_outcar.to("lammps/lmp", "conf.lmp", frame_idx=0)
58+
```
59+
The first frames of `d_outcar` will be dumped to 'conf.lmp'
60+
```python
61+
d_outcar.to("vasp/poscar", "POSCAR", frame_idx=-1)
62+
```
63+
The last frames of `d_outcar` will be dumped to 'POSCAR'.
64+
65+
The data stored in `LabeledSystem` can be dumped to deepmd-kit raw format, for example
66+
```python
67+
d_outcar.to("deepmd/raw", "dpmd_raw")
68+
```
69+
Or a simpler command:
70+
```python
71+
dpdata.LabeledSystem("OUTCAR").to("deepmd/raw", "dpmd_raw")
72+
```
73+
Frame selection can be implemented by
74+
```python
75+
dpdata.LabeledSystem("OUTCAR").sub_system([0, -1]).to("deepmd/raw", "dpmd_raw")
76+
```
77+
by which only the first and last frames are dumped to `dpmd_raw`.
78+
79+
80+
### replicate
81+
dpdata will create a super cell of the current atom configuration.
82+
```python
83+
dpdata.System("./POSCAR").replicate(
84+
(
85+
1,
86+
2,
87+
3,
88+
)
89+
)
90+
```
91+
tuple(1,2,3) means don't copy atom configuration in x direction, make 2 copys in y direction, make 3 copys in z direction.
92+
93+
94+
### perturb
95+
By the following example, each frame of the original system (`dpdata.System('./POSCAR')`) is perturbed to generate three new frames. For each frame, the cell is perturbed by 5% and the atom positions are perturbed by 0.6 Angstrom. `atom_pert_style` indicates that the perturbation to the atom positions is subject to normal distribution. Other available options to `atom_pert_style` are`uniform` (uniform in a ball), and `const` (uniform on a sphere).
96+
```python
97+
perturbed_system = dpdata.System("./POSCAR").perturb(
98+
pert_num=3,
99+
cell_pert_fraction=0.05,
100+
atom_pert_distance=0.6,
101+
atom_pert_style="normal",
102+
)
103+
print(perturbed_system.data)
104+
```
105+
106+
### replace
107+
By the following example, Random 8 Hf atoms in the system will be replaced by Zr atoms with the atom postion unchanged.
108+
```python
109+
s = dpdata.System("tests/poscars/POSCAR.P42nmc", fmt="vasp/poscar")
110+
s.replace("Hf", "Zr", 8)
111+
s.to_vasp_poscar("POSCAR.P42nmc.replace")
112+
```

0 commit comments

Comments
 (0)