Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dpdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from . import lammps, md, vasp
from .bond_order_system import BondOrderSystem
from .formats import lammps, md, vasp
from .system import LabeledSystem, MultiSystems, System

try:
Expand Down
12 changes: 6 additions & 6 deletions dpdata/bond_order_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import numpy as np

import dpdata.rdkit.utils
from dpdata.rdkit.sanitize import Sanitizer
import dpdata.formats.rdkit.utils
from dpdata.formats.rdkit.sanitize import Sanitizer
from dpdata.system import Axis, DataType, System

# import dpdata.rdkit.mol2
# import dpdata.formats.rdkit.mol2


class BondOrderSystem(System):
Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(
self.sanitizer = Sanitizer(sanitize_level, raise_errors, verbose)

if data:
mol = dpdata.rdkit.utils.system_data_to_mol(data)
mol = dpdata.formats.rdkit.utils.system_data_to_mol(data)
self.from_rdkit_mol(mol)
if file_name:
self.from_fmt(
Expand Down Expand Up @@ -161,7 +161,7 @@ def __add__(self, other):
# magic method "+" operation
# '''
# if isinstance(other, BondOrderSystem):
# if dpdata.rdkit.utils.check_same_molecule(self.rdkit_mol, other.rdkit_mol):
# if dpdata.formats.rdkit.utils.check_same_molecule(self.rdkit_mol, other.rdkit_mol):
# self.__class__(self, data=other.data)
# else:
# raise RuntimeError("The two systems are not of the same topology.")
Expand All @@ -171,7 +171,7 @@ def __add__(self, other):
def from_rdkit_mol(self, rdkit_mol):
"""Initialize from a rdkit.Chem.rdchem.Mol object."""
rdkit_mol = self.sanitizer.sanitize(rdkit_mol)
self.data = dpdata.rdkit.utils.mol_to_system_data(rdkit_mol)
self.data = dpdata.formats.rdkit.utils.mol_to_system_data(rdkit_mol)
self.data["bond_dict"] = dict(
[(f"{int(bond[0])}-{int(bond[1])}", bond[2]) for bond in self.data["bonds"]]
)
Expand Down
1 change: 1 addition & 0 deletions dpdata/formats/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Format modules for dpdata
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check current directory structure and file content
pwd
echo "=== File content ==="
cat -n dpdata/formats/__init__.py 2>/dev/null || echo "File not found"

echo -e "\n=== Checking if ruff is available ==="
which ruff || echo "ruff not found, will attempt to install"

echo -e "\n=== Installing ruff if needed ==="
pip install ruff -q

echo -e "\n=== Running ruff checks ==="
ruff check dpdata/ --statistics

echo -e "\n=== Running ruff format check (dry-run) ==="
ruff format --check dpdata/

Repository: deepmodeling/dpdata

Length of output: 2279


Package initializer structure is correct; however, ruff linting shows 386 errors across dpdata/ that must be resolved before merge.

The file itself is fine, but the broader directory has significant lint violations:

  • 117 TRY003 (raise-vanilla-args)
  • 95 ARG002 (unused-method-argument)
  • 24 B007 (unused-loop-control-variable)
  • 22 B028 (no-explicit-stacklevel)
  • 20 F841 (unused-variable)
  • And 131 more violations across multiple rules

Formatting is compliant (107 files already formatted). Address the lint errors with ruff check --fix dpdata/ before merge to comply with the coding guidelines for dpdata/**/*.py.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dpdata/formats/__init__.py` at line 1, The repo has widespread ruff lint
violations under the dpdata package; run ruff check --fix dpdata/ to
automatically apply fixes and then manually address remaining issues: replace
bare "raise" usage with "raise from" or preserve exception context for TRY003,
mark unused method args in class methods (e.g., in any dpdata.* classes) with a
leading underscore or remove them to fix ARG002, remove or use unused variables
to fix F841 and B007 (or prefix loop control variables with _), add explicit
stacklevel arguments to warnings.warn calls to resolve B028, and eliminate
unused imports/variables across the package; iterate until ruff reports no
errors and commit the cleaned dpdata package (starting point: dpdata.__init__
and other modules under dpdata/).

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dpdata/abacus/scf.py → dpdata/formats/abacus/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from dpdata.utils import open_file

from ..unit import LengthConversion, PressureConversion
from ...unit import LengthConversion, PressureConversion
from .stru import get_frame_from_stru

bohr2ang = LengthConversion("bohr", "angstrom").value()
Expand Down
2 changes: 1 addition & 1 deletion dpdata/abacus/stru.py → dpdata/formats/abacus/stru.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np

from ..unit import LengthConversion
from ...unit import LengthConversion

bohr2ang = LengthConversion("bohr", "angstrom").value()

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions dpdata/amber/md.py → dpdata/formats/amber/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import numpy as np

from dpdata.amber.mask import pick_by_amber_mask
from dpdata.formats.amber.mask import pick_by_amber_mask
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n dpdata/formats/amber/md.py | head -20

Repository: deepmodeling/dpdata

Length of output: 598


🏁 Script executed:

ruff check dpdata/formats/amber/md.py

Repository: deepmodeling/dpdata

Length of output: 1706


Fix ruff linting violations before merge.

The file has 3 ruff violations:

  • Line 15 (RUF005): Replace ["X"] + ELEMENTS with ["X", *ELEMENTS]
  • Line 96 (TRY003): Avoid specifying long exception messages outside the exception class; move "Unsupported cells" into the exception
  • Line 118 (TRY003): Avoid specifying long exception messages outside the exception class; move "Please provide one of mden_file and mdout_file" into the exception

Run ruff check dpdata/ to verify compliance and ruff format dpdata/ to auto-fix where possible.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dpdata/formats/amber/md.py` at line 8, Replace the list construction ["X"] +
ELEMENTS with the unpacking form ["X", *ELEMENTS] where the atom/elements list
is defined; find the constant that uses ELEMENTS and update it. For the two
exception occurrences, move the literal messages into the exception constructors
instead of passing them outside: replace patterns that raise exceptions with
external messages to raise RuntimeError("Unsupported cells") and raise
ValueError("Please provide one of mden_file and mdout_file") (or the original
exception types used) so the strings "Unsupported cells" and "Please provide one
of mden_file and mdout_file" become the exception's message. Ensure you update
the raise sites in dpdata.formats.amber.md (the blocks that handle cell parsing
and the mden/mdout argument validation) and run ruff check/format afterwards.

from dpdata.unit import EnergyConversion
from dpdata.utils import open_file

from ..periodic_table import ELEMENTS
from ...periodic_table import ELEMENTS

kcalmol2eV = EnergyConversion("kcal_mol", "eV").value()
symbols = ["X"] + ELEMENTS
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dpdata/cp2k/output.py → dpdata/formats/cp2k/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np

from ..unit import (
from ...unit import (
EnergyConversion,
ForceConversion,
LengthConversion,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions dpdata/gaussian/fchk.py → dpdata/formats/gaussian/fchk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
if TYPE_CHECKING:
from dpdata.utils import FileType

from ..periodic_table import ELEMENTS
from ..unit import (
from ...periodic_table import ELEMENTS
from ...unit import (
EnergyConversion,
ForceConversion,
HessianConversion,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions dpdata/gaussian/log.py → dpdata/formats/gaussian/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
if TYPE_CHECKING:
from dpdata.utils import FileType

from ..periodic_table import ELEMENTS
from ..unit import EnergyConversion, ForceConversion, LengthConversion
from ...periodic_table import ELEMENTS
from ...unit import EnergyConversion, ForceConversion, LengthConversion

length_convert = LengthConversion("bohr", "angstrom").value()
energy_convert = EnergyConversion("hartree", "eV").value()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion dpdata/gromacs/gro.py → dpdata/formats/gromacs/gro.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if TYPE_CHECKING:
from dpdata.utils import FileType

from ..unit import LengthConversion
from ...unit import LengthConversion

nm2ang = LengthConversion("nm", "angstrom").value()
ang2nm = LengthConversion("angstrom", "nm").value()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dpdata/openmx/omx.py → dpdata/formats/openmx/omx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if TYPE_CHECKING:
from dpdata.utils import FileType

from ..unit import (
from ...unit import (
EnergyConversion,
ForceConversion,
LengthConversion,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from ..periodic_table import ELEMENTS
from ...periodic_table import ELEMENTS


def _to_system_data_lower(lines):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np

from ..periodic_table import ELEMENTS
from ...periodic_table import ELEMENTS


def system_info(lines, type_idx_zero=False):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dpdata/qe/traj.py → dpdata/formats/qe/traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import os

from ..unit import (
from ...unit import (
EnergyConversion,
ForceConversion,
LengthConversion,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dpdata/plugins/3dmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from dpdata.format import Format
from dpdata.xyz.xyz import coord_to_xyz
from dpdata.formats.xyz.xyz import coord_to_xyz


@Format.register("3dmol")
Expand Down
14 changes: 7 additions & 7 deletions dpdata/plugins/abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import numpy as np

import dpdata.abacus.md
import dpdata.abacus.relax
import dpdata.abacus.scf
from dpdata.abacus.stru import get_frame_from_stru, make_unlabeled_stru
import dpdata.formats.abacus.md
import dpdata.formats.abacus.relax
import dpdata.formats.abacus.scf
from dpdata.data_type import Axis, DataType
from dpdata.format import Format
from dpdata.formats.abacus.stru import get_frame_from_stru, make_unlabeled_stru
from dpdata.utils import open_file

if TYPE_CHECKING:
Expand Down Expand Up @@ -90,7 +90,7 @@ def register_move_data(data):
class AbacusSCFFormat(Format):
# @Format.post("rot_lower_triangular")
def from_labeled_system(self, file_name, **kwargs):
data = dpdata.abacus.scf.get_frame(file_name)
data = dpdata.formats.abacus.scf.get_frame(file_name)
register_mag_data(data)
register_move_data(data)
return data
Expand All @@ -102,7 +102,7 @@ def from_labeled_system(self, file_name, **kwargs):
class AbacusMDFormat(Format):
# @Format.post("rot_lower_triangular")
def from_labeled_system(self, file_name, **kwargs):
data = dpdata.abacus.md.get_frame(file_name)
data = dpdata.formats.abacus.md.get_frame(file_name)
register_mag_data(data)
register_move_data(data)
return data
Expand All @@ -114,7 +114,7 @@ def from_labeled_system(self, file_name, **kwargs):
class AbacusRelaxFormat(Format):
# @Format.post("rot_lower_triangular")
def from_labeled_system(self, file_name, **kwargs):
data = dpdata.abacus.relax.get_frame(file_name)
data = dpdata.formats.abacus.relax.get_frame(file_name)
register_mag_data(data)
register_move_data(data)
return data
14 changes: 7 additions & 7 deletions dpdata/plugins/amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import subprocess as sp
import tempfile

import dpdata.amber.md
import dpdata.amber.sqm
import dpdata.formats.amber.md
import dpdata.formats.amber.sqm
from dpdata.driver import Driver, Minimizer
from dpdata.format import Format
from dpdata.utils import open_file
Expand All @@ -26,7 +26,7 @@ def from_system(
parm7_file = file_name + ".parm7"
if nc_file is None:
nc_file = file_name + ".nc"
return dpdata.amber.md.read_amber_traj(
return dpdata.formats.amber.md.read_amber_traj(
parm7_file=parm7_file,
nc_file=nc_file,
use_element_symbols=use_element_symbols,
Expand Down Expand Up @@ -55,7 +55,7 @@ def from_labeled_system(
mden_file = file_name + ".mden"
if mdout_file is None:
mdout_file = file_name + ".mdout"
return dpdata.amber.md.read_amber_traj(
return dpdata.formats.amber.md.read_amber_traj(
parm7_file, nc_file, mdfrc_file, mden_file, mdout_file, use_element_symbols
)

Expand All @@ -64,11 +64,11 @@ def from_labeled_system(
class SQMOutFormat(Format):
def from_system(self, fname, **kwargs):
"""Read from ambertools sqm.out."""
return dpdata.amber.sqm.parse_sqm_out(fname)
return dpdata.formats.amber.sqm.parse_sqm_out(fname)

def from_labeled_system(self, fname, **kwargs):
"""Read from ambertools sqm.out."""
data = dpdata.amber.sqm.parse_sqm_out(fname)
data = dpdata.formats.amber.sqm.parse_sqm_out(fname)
assert "forces" in list(data.keys()), f"No forces in {fname}"
return data

Expand Down Expand Up @@ -104,7 +104,7 @@ def to_system(self, data, fname=None, frame_idx=0, **kwargs):
mult : int, default=1
multiplicity. Only 1 is allowed.
"""
return dpdata.amber.sqm.make_sqm_in(data, fname, frame_idx, **kwargs)
return dpdata.formats.amber.sqm.make_sqm_in(data, fname, frame_idx, **kwargs)


@Driver.register("sqm")
Expand Down
6 changes: 3 additions & 3 deletions dpdata/plugins/cp2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import glob

import dpdata.cp2k.output
from dpdata.cp2k.output import Cp2kSystems
import dpdata.formats.cp2k.output
from dpdata.format import Format
from dpdata.formats.cp2k.output import Cp2kSystems

string_warning = """
Hi, you got an error from dpdata,
Expand Down Expand Up @@ -42,7 +42,7 @@ def from_labeled_system(self, file_name, restart=False, **kwargs):
data["energies"],
data["forces"],
tmp_virial,
) = dpdata.cp2k.output.get_frames(file_name)
) = dpdata.formats.cp2k.output.get_frames(file_name)
if tmp_virial is not None:
data["virials"] = tmp_virial
return data
Expand Down
Loading
Loading