chore: switches from black and isort to ruff

This commit is contained in:
2026-02-26 17:40:26 -03:00
parent d89124b1e8
commit 5d76e49f89
20 changed files with 286 additions and 77 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
from typing_extensions import TYPE_CHECKING
if TYPE_CHECKING:
from nptyping import Float, NDArray, Shape
@@ -319,7 +320,7 @@ class Molecule:
self.com[0], self.com[1], self.com[2]
)
)
inertia = self.inertia_tensor()
self.inertia_tensor()
evals, evecs = self.principal_axes()
logger.info(

View File

@@ -1,11 +1,10 @@
from diceplayer import logger
from diceplayer.shared.environment.molecule import Molecule
from diceplayer.shared.utils.misc import BOHR2ANG
from diceplayer.shared.utils.ptable import atomsymb
import numpy as np
from numpy import linalg
from typing_extensions import List, TextIO, Tuple
from typing_extensions import List, Tuple
import math
from copy import deepcopy
@@ -92,8 +91,10 @@ class System:
try:
evals, evecs = linalg.eigh(rr)
except:
raise RuntimeError("Error: diagonalization of RR matrix did not converge")
except Exception as err:
raise RuntimeError(
"Error: diagonalization of RR matrix did not converge"
) from err
a1 = evecs[:, 2].T
a2 = evecs[:, 1].T

View File

@@ -1 +1,4 @@
from .__interface import Interface
__all__ = ["Interface"]

View File

@@ -17,6 +17,7 @@ import time
from multiprocessing import Process, connection
from pathlib import Path
DICE_END_FLAG: Final[str] = "End of simulation"
DICE_FLAG_LINE: Final[int] = -2
UMAANG3_TO_GCM3: Final[float] = 1.6605
@@ -206,10 +207,10 @@ class DiceInterface(Interface):
f.write(f"temp = {self.step.dice.temp}\n")
if self.step.dice.randominit == "first" and cycle > 1:
f.write(f"init = yesreadxyz\n")
f.write("init = yesreadxyz\n")
f.write(f"nstep = {self.step.altsteps}\n")
else:
f.write(f"init = yes\n")
f.write("init = yes\n")
f.write(f"nstep = {self.step.dice.nstep[0]}\n")
f.write("vstep = 0\n")
@@ -301,7 +302,7 @@ class DiceInterface(Interface):
f.write(f"press = {self.step.dice.press}\n")
f.write(f"temp = {self.step.dice.temp}\n")
f.write(f"nstep = 5\n")
f.write("nstep = 5\n")
f.write(f"vstep = {int(self.step.dice.nstep[2] / 5)}\n")
f.write("init = no\n")

View File

@@ -60,13 +60,13 @@ class GaussianInterface(Interface):
def _copy_chk_file_from_previous_step(self, cycle: int):
current_chk_file_path = Path(
self.step.simulation_dir, f"step{cycle:02d}", "qm", f"asec.chk"
self.step.simulation_dir, f"step{cycle:02d}", "qm", "asec.chk"
)
if current_chk_file_path.exists():
raise FileExistsError(f"File {current_chk_file_path} already exists.")
previous_chk_file_path = Path(
self.step.simulation_dir, f"step{(cycle - 1):02d}", "qm", f"asec.chk"
self.step.simulation_dir, f"step{(cycle - 1):02d}", "qm", "asec.chk"
)
if not previous_chk_file_path.exists():
raise FileNotFoundError(f"File {previous_chk_file_path} does not exist.")
@@ -139,7 +139,7 @@ class GaussianInterface(Interface):
charges_nsites = int(charges.pop(0))
if int(charges_nsites) != total_nsites:
raise ValueError(
f"Number of sites does not match total number of sites."
"Number of sites does not match total number of sites."
)
thickness.append(self._calculate_proc_thickness(charges))
@@ -166,7 +166,7 @@ class GaussianInterface(Interface):
].strip()
):
raise SyntaxError(
f"Error: Invalid Dice Output. Atom type does not match."
"Error: Invalid Dice Output. Atom type does not match."
)
new_molecule.add_atom(
@@ -216,7 +216,7 @@ class GaussianInterface(Interface):
def _make_gaussian_input_file(self, cycle: int, asec_charges: list[dict]) -> None:
gaussian_input_file_path = Path(
self.step.simulation_dir, f"step{cycle:02d}", "qm", f"asec.gjf"
self.step.simulation_dir, f"step{cycle:02d}", "qm", "asec.gjf"
)
with open(gaussian_input_file_path, "w") as gaussian_input_file:

View File

@@ -6,6 +6,7 @@ import shutil
import sys
import time
####################################### constants ######################################
@@ -36,7 +37,7 @@ def compress_files_1mb(path):
with open(file, "rb") as f_in:
with gzip.open(filegz, "wb") as f_out:
shutil.copyfileobj(f_in, f_out)
except:
except Exception as _:
sys.exit("Error: cannot compress file {}".format(file))
os.chdir(working_dir)
@@ -52,7 +53,7 @@ def make_step_dir(cycle):
sys.exit("Error: a file or directory {} already exists".format(step_dir))
try:
os.makedirs(path)
except:
except Exception as _:
sys.exit("Error: cannot make directory {}".format(step_dir))
@@ -62,5 +63,5 @@ def make_qm_dir(cycle):
path = sim_dir + os.sep + step_dir + os.sep + "qm"
try:
os.makedirs(path)
except:
except Exception as _:
sys.exit("Error: cannot make directory {}".format(path))