Skip to content

Commit ffa52c5

Browse files
lint and automatic lint (#413)
Fix #344. To lint codes, this PR uses a popular tool, [pre-commit](https://pre-commit.com/). `.pre-commit-config.yaml` shows all hooks used, including [black](https://github.com/psf/black) and some common fixes. It can add a git hook to `git commit`. Thus, everything committed can be already formatted. In addition, there is also a [CI](https://pre-commit.ci/) to fix PRs. This way, we can ensure that everything new will also be formatted. This PR introduces a huge change history to almost all files, but it's a necessary step to start linting our codes. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7b0f44b commit ffa52c5

File tree

166 files changed

+6957
-4954
lines changed

Some content is hidden

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

166 files changed

+6957
-4954
lines changed

.github/ISSUE_TEMPLATE/request-for-help.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Before asking questions, you can
1313
search the previous issues or discussions
1414
check the [README](https://github.com/deepmodeling/dpdata/#readme).
1515

16-
Please **do not** post requests for help (e.g. with installing or using dpdata) here.
16+
Please **do not** post requests for help (e.g. with installing or using dpdata) here.
1717
Instead go to [discussions](https://github.com/deepmodeling/dpdata/discussions).
1818

1919
This issue tracker is for tracking dpdata development related issues only.

.github/workflows/pub-pypi.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ jobs:
3636
uses: pypa/gh-action-pypi-publish@master
3737
with:
3838
password: ${{ secrets.PYPI_API_TOKEN }}
39-

.github/workflows/test_import.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ jobs:
1515
architecture: 'x64'
1616
- run: python -m pip install .
1717
- run: python -c 'import dpdata'
18-

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.4.0
6+
hooks:
7+
# there are many log files in tests
8+
# TODO: seperate py files and log files
9+
- id: trailing-whitespace
10+
exclude: "^tests/.*$"
11+
- id: end-of-file-fixer
12+
exclude: "^tests/.*$"
13+
- id: check-yaml
14+
- id: check-json
15+
- id: check-added-large-files
16+
- id: check-merge-conflict
17+
- id: check-symlinks
18+
- id: check-toml
19+
# Python
20+
- repo: https://github.com/psf/black
21+
rev: 22.12.0
22+
hooks:
23+
- id: black-jupyter
24+
ci:
25+
autoupdate_branch: devel

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dpdata only works with python 3.7 or above.
33

44

55
# Installation
6-
One can download the source code of dpdata by
6+
One can download the source code of dpdata by
77
```bash
88
git clone https://github.com/deepmodeling/dpdata.git dpdata
99
```
@@ -25,10 +25,10 @@ This section gives some examples on how dpdata works. Firstly one needs to impor
2525
```python
2626
import dpdata
2727
```
28-
The typicall workflow of `dpdata` is
28+
The typicall workflow of `dpdata` is
2929

3030
1. Load data from vasp or lammps or deepmd-kit data files.
31-
2. Manipulate data
31+
2. Manipulate data
3232
3. Dump data to in a desired format
3333

3434

@@ -41,9 +41,9 @@ or let dpdata infer the format (`vasp/poscar`) of the file from the file name ex
4141
d_poscar = dpdata.System('my.POSCAR')
4242
```
4343
The number of atoms, atom types, coordinates are loaded from the `POSCAR` and stored to a data `System` called `d_poscar`.
44-
A data `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 `System`.
44+
A data `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 `System`.
4545
It is noted that `POSCAR` only contains one frame.
46-
If the multiple frames stored in, for example, a `OUTCAR` is wanted,
46+
If the multiple frames stored in, for example, a `OUTCAR` is wanted,
4747
```python
4848
d_outcar = dpdata.LabeledSystem('OUTCAR')
4949
```
@@ -53,9 +53,9 @@ The `System` or `LabeledSystem` can be constructed from the following file forma
5353

5454
| Software| format | multi frames | labeled | class | format key |
5555
| ------- | :--- | :---: | :---: | :--- | :--- |
56-
| vasp | poscar | False | False | System | 'vasp/poscar' |
57-
| vasp | outcar | True | True | LabeledSystem | 'vasp/outcar' |
58-
| vasp | xml | True | True | LabeledSystem | 'vasp/xml' |
56+
| vasp | poscar | False | False | System | 'vasp/poscar' |
57+
| vasp | outcar | True | True | LabeledSystem | 'vasp/outcar' |
58+
| vasp | xml | True | True | LabeledSystem | 'vasp/xml' |
5959
| lammps | lmp | False | False | System | 'lammps/lmp' |
6060
| lammps | dump | True | False | System | 'lammps/dump' |
6161
| deepmd | raw | True | False | System | 'deepmd/raw' |
@@ -89,7 +89,7 @@ The `System` or `LabeledSystem` can be constructed from the following file forma
8989

9090
The 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.
9191

92-
Use `dpdata.MultiSystems.from_dir` to read from a directory, `dpdata.MultiSystems` will walk in the directory
92+
Use `dpdata.MultiSystems.from_dir` to read from a directory, `dpdata.MultiSystems` will walk in the directory
9393
Recursively and find all file with specific file_name. Supports all the file formats that `dpdata.LabeledSystem` supports.
9494

9595
Use `dpdata.MultiSystems.from_file` to read from single file. Single-file support is available for the `quip/gap/xyz` and `ase/structure` formats.
@@ -148,7 +148,7 @@ coords = d_outcar['coords']
148148
```
149149
Available properties are (nframe: number of frames in the system, natoms: total number of atoms in the system)
150150

151-
| key | type | dimension | are labels | description
151+
| key | type | dimension | are labels | description
152152
| --- | --- | --- | --- | ---
153153
| 'atom_names' | list of str | ntypes | False | The name of each atom type
154154
| 'atom_numbs' | list of int | ntypes | False | The number of atoms of each atom type
@@ -186,7 +186,7 @@ dpdata.LabeledSystem('OUTCAR').sub_system([0,-1]).to('deepmd/raw', 'dpmd_raw')
186186
by which only the first and last frames are dumped to `dpmd_raw`.
187187

188188

189-
## replicate
189+
## replicate
190190
dpdata will create a super cell of the current atom configuration.
191191
```python
192192
dpdata.System('./POSCAR').replicate((1,2,3,) )
@@ -197,9 +197,9 @@ tuple(1,2,3) means don't copy atom configuration in x direction, make 2 copys in
197197
## perturb
198198
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).
199199
```python
200-
perturbed_system = dpdata.System('./POSCAR').perturb(pert_num=3,
201-
cell_pert_fraction=0.05,
202-
atom_pert_distance=0.6,
200+
perturbed_system = dpdata.System('./POSCAR').perturb(pert_num=3,
201+
cell_pert_fraction=0.05,
202+
atom_pert_distance=0.6,
203203
atom_pert_style='normal')
204204
print(perturbed_system.data)
205205
```
@@ -213,7 +213,7 @@ s.to_vasp_poscar('POSCAR.P42nmc.replace')
213213
```
214214

215215
# BondOrderSystem
216-
A new class `BondOrderSystem` which inherits from 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).
216+
A new class `BondOrderSystem` which inherits from 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).
217217
```python
218218
import dpdata
219219
system_1 = dpdata.BondOrderSystem("tests/bond_order/CH3OH.mol", fmt="mol") # read from .mol file
@@ -242,7 +242,7 @@ According to our test, our sanitization procedure can successfully read 4852 sma
242242

243243
```python
244244
import dpdata
245-
245+
246246
for sdf_file in glob.glob("bond_order/refined-set-ligands/obabel/*sdf"):
247247
syst = dpdata.BondOrderSystem(sdf_file, sanitize_level='high', verbose=False)
248248
```

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ help:
1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
20-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616
import sys
1717
import subprocess as sp
1818
from datetime import date
19-
sys.path.insert(0, os.path.abspath('..'))
19+
20+
sys.path.insert(0, os.path.abspath(".."))
2021

2122

2223
# -- Project information -----------------------------------------------------
2324

24-
project = 'dpdata'
25-
copyright = '2019-%d, DeepModeling ' % date.today().year
26-
author = 'Han Wang'
25+
project = "dpdata"
26+
copyright = "2019-%d, DeepModeling " % date.today().year
27+
author = "Han Wang"
2728

2829
# The short X.Y version
29-
version = '0.0'
30+
version = "0.0"
3031
# The full version, including alpha/beta/rc tags
31-
release = '0.0.0-rc'
32+
release = "0.0.0-rc"
3233

3334

3435
# -- General configuration ---------------------------------------------------
@@ -41,27 +42,27 @@
4142
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4243
# ones.
4344
extensions = [
44-
'deepmodeling_sphinx',
45-
'sphinx_rtd_theme',
46-
'sphinx.ext.mathjax',
47-
'sphinx.ext.viewcode',
48-
'sphinx.ext.intersphinx',
49-
'numpydoc',
50-
'm2r2',
51-
'sphinxarg.ext',
45+
"deepmodeling_sphinx",
46+
"sphinx_rtd_theme",
47+
"sphinx.ext.mathjax",
48+
"sphinx.ext.viewcode",
49+
"sphinx.ext.intersphinx",
50+
"numpydoc",
51+
"m2r2",
52+
"sphinxarg.ext",
5253
]
5354

5455
# Add any paths that contain templates here, relative to this directory.
55-
templates_path = ['_templates']
56+
templates_path = ["_templates"]
5657

5758
# The suffix(es) of source filenames.
5859
# You can specify multiple suffix as a list of string:
5960
#
6061
# source_suffix = ['.rst', '.md']
61-
source_suffix = ['.rst', '.md']
62+
source_suffix = [".rst", ".md"]
6263

6364
# The master toctree document.
64-
master_doc = 'index'
65+
master_doc = "index"
6566

6667
# The language for content autogenerated by Sphinx. Refer to documentation
6768
# for a list of supported languages.
@@ -73,18 +74,18 @@
7374
# List of patterns, relative to source directory, that match files and
7475
# directories to ignore when looking for source files.
7576
# This pattern also affects html_static_path and html_extra_path .
76-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
77+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7778

7879
# The name of the Pygments (syntax highlighting) style to use.
79-
pygments_style = 'sphinx'
80+
pygments_style = "sphinx"
8081

8182

8283
# -- Options for HTML output -------------------------------------------------
8384

8485
# The theme to use for HTML and HTML Help pages. See the documentation for
8586
# a list of builtin themes.
8687
#
87-
html_theme = 'sphinx_rtd_theme'
88+
html_theme = "sphinx_rtd_theme"
8889

8990
# Theme options are theme-specific and customize the look and feel of a theme
9091
# further. For a list of options available for each theme, see the
@@ -95,7 +96,7 @@
9596
# Add any paths that contain custom static files (such as style sheets) here,
9697
# relative to this directory. They are copied after the builtin static files,
9798
# so a file named "default.css" will overwrite the builtin "default.css".
98-
#html_static_path = ['_static']
99+
# html_static_path = ['_static']
99100

100101
# Custom sidebar templates, must be a dictionary that maps document names
101102
# to template names.
@@ -111,7 +112,7 @@
111112
# -- Options for HTMLHelp output ---------------------------------------------
112113

113114
# Output file base name for HTML help builder.
114-
htmlhelp_basename = 'dpdatadoc'
115+
htmlhelp_basename = "dpdatadoc"
115116

116117

117118
# -- Options for LaTeX output ------------------------------------------------
@@ -120,15 +121,12 @@
120121
# The paper size ('letterpaper' or 'a4paper').
121122
#
122123
# 'papersize': 'letterpaper',
123-
124124
# The font size ('10pt', '11pt' or '12pt').
125125
#
126126
# 'pointsize': '10pt',
127-
128127
# Additional stuff for the LaTeX preamble.
129128
#
130129
# 'preamble': '',
131-
132130
# Latex figure (float) alignment
133131
#
134132
# 'figure_align': 'htbp',
@@ -138,19 +136,15 @@
138136
# (source start file, target name, title,
139137
# author, documentclass [howto, manual, or own class]).
140138
latex_documents = [
141-
(master_doc, 'dpdata.tex', 'dpdata Documentation',
142-
'Han Wang', 'manual'),
139+
(master_doc, "dpdata.tex", "dpdata Documentation", "Han Wang", "manual"),
143140
]
144141

145142

146143
# -- Options for manual page output ------------------------------------------
147144

148145
# One entry per manual page. List of tuples
149146
# (source start file, name, description, authors, manual section).
150-
man_pages = [
151-
(master_doc, 'dpdata', 'dpdata Documentation',
152-
[author], 1)
153-
]
147+
man_pages = [(master_doc, "dpdata", "dpdata Documentation", [author], 1)]
154148

155149

156150
# -- Options for Texinfo output ----------------------------------------------
@@ -159,26 +153,47 @@
159153
# (source start file, target name, title, author,
160154
# dir menu entry, description, category)
161155
texinfo_documents = [
162-
(master_doc, 'dpdata', 'dpdata Documentation',
163-
author, 'dpdata', 'One line description of project.',
164-
'Miscellaneous'),
156+
(
157+
master_doc,
158+
"dpdata",
159+
"dpdata Documentation",
160+
author,
161+
"dpdata",
162+
"One line description of project.",
163+
"Miscellaneous",
164+
),
165165
]
166166

167167

168168
# -- Extension configuration -------------------------------------------------
169169
def run_apidoc(_):
170170
from sphinx.ext.apidoc import main
171-
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
171+
172+
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
172173
cur_dir = os.path.abspath(os.path.dirname(__file__))
173174
module = os.path.join(cur_dir, "..", "dpdata")
174-
main(['-M', '--tocfile', 'api', '-H', 'API documentation', '-o', os.path.join(cur_dir, "api"), module, '--force'])
175+
main(
176+
[
177+
"-M",
178+
"--tocfile",
179+
"api",
180+
"-H",
181+
"API documentation",
182+
"-o",
183+
os.path.join(cur_dir, "api"),
184+
module,
185+
"--force",
186+
]
187+
)
188+
175189

176190
def run_formats(_):
177191
sp.check_output([sys.executable, "make_format.py"])
178192

193+
179194
def setup(app):
180-
app.connect('builder-inited', run_apidoc)
181-
app.connect('builder-inited', run_formats)
195+
app.connect("builder-inited", run_apidoc)
196+
app.connect("builder-inited", run_formats)
182197

183198

184199
intersphinx_mapping = {

docs/credits.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Authors
22
=======
33

4-
.. git-shortlog-authors::
4+
.. git-shortlog-authors::

docs/formats.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ dpdata supports the following formats:
66
.. csv-table:: Supported Formats
77
:file: formats.csv
88
:header-rows: 1
9-

0 commit comments

Comments
 (0)