Skip to content

Commit

Permalink
pylint fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
97gamjak committed May 11, 2024
1 parent d79a4f2 commit 15bbc36
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 127 deletions.
3 changes: 2 additions & 1 deletion .style.yapf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ BLANK_LINE_BEFORE_CLASS_DOCSTRING = true
BLANK_LINE_BEFORE_MODULE_DOCSTRING = true
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true
BLANK_LINES_AROUND_TOP_LEVEL_DEFINITION = 3
SPLIT_PENALTY_IMPORT_NAMES=1000
SPLIT_PENALTY_IMPORT_NAMES=1000
SPACES_BEFORE_COMMENT=2
27 changes: 18 additions & 9 deletions PQAnalysis/analysis/rdf/rdf_output_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from .rdf import RDF



class RDFDataWriter(BaseWriter):

"""
Class for writing the data of an
:py:class:`~PQAnalysis.analysis.rdf.rdf.RDF`
Expand All @@ -34,14 +36,14 @@ def __init__(self, filename: str) -> None:
super().__init__(filename)

@runtime_type_checking
def write(self,
data: Tuple[Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray
]
):
def write(
self,
data: Tuple[Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray,
Np1DNumberArray]
):
"""
Writes the data to the file.
Expand All @@ -55,12 +57,19 @@ def write(self,

for i in range(len(data[0])):
print(
f"{data[0][i]} {data[1][i]} {data[2][i]} {data[3][i]} {data[4][i]}", file=self.file)
(
f"{data[0][i]} {data[1][i]} {data[2][i]} "
f"{data[3][i]} {data[4][i]}"
),
file=self.file
)

super().close()



class RDFLogWriter(BaseWriter):

"""
Class for writing the log (setup parameters) of an
:py:class:`~PQAnalysis.analysis.rdf.rdf.RDF` analysis
Expand Down
5 changes: 3 additions & 2 deletions PQAnalysis/core/atom/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ def __init__(
If his parameter is not given, the name parameter is used to determine
the element type of the atom_type.
use_guess_element : bool, optional
Whether to use the guess_element function to determine the element type of the atom_type
by its name, by default True
Whether to use the guess_element function to determine
the element type of the atom_type by its name,
by default True
Raises
------
Expand Down
5 changes: 4 additions & 1 deletion PQAnalysis/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from beartype.typing import Any, List



class BaseEnumFormat(Enum):

"""
An enumeration super class of the various supported trajectory formats.
"""
Expand All @@ -27,7 +29,8 @@ def member_repr(cls) -> str:
@classmethod
def value_repr(cls) -> str:
"""
This method returns a string representation of the values of the members of the enumeration.
This method returns a string representation of
the values of the members of the enumeration.
Returns
-------
Expand Down
3 changes: 2 additions & 1 deletion PQAnalysis/io/conversion_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def traj2box(
mode: FileWritingMode | str = "w"
) -> None:
"""
Converts multiple trajectory files to a box file and prints it to stdout or writes it to a file.
Converts multiple trajectory files to a box file and
prints it to stdout or writes it to a file.
Without the vmd option the output is printed in a data file format.
The first column represents the step starting from 1, the second to fourth column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

from beartype.typing import List

from PQAnalysis.io.input_file_reader.exceptions import InputFileError, InputFileWarning
from PQAnalysis.io.input_file_reader.exceptions import InputFileError
from PQAnalysis.io.input_file_reader.input_file_parser import InputFileParser
from PQAnalysis.io.input_file_reader.formats import InputFileFormat
from PQAnalysis.utils.custom_logging import setup_logger
from PQAnalysis import __package_name__

from ._file_mixin import _FileMixin
from ._selection_mixin import _SelectionMixin
from ._positions_mixin import _PositionsMixin
from PQAnalysis.utils.custom_logging import setup_logger
from PQAnalysis import __package_name__



Expand Down
70 changes: 41 additions & 29 deletions PQAnalysis/io/traj_file/frame_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
from .exceptions import FrameReaderError



class _FrameReader:

"""
This class provides methods for reading a frame from a string.
The string can be a single frame or a whole trajectory.
Expand All @@ -36,7 +38,10 @@ class can be used to read a whole trajectory as well as
logger = logging.getLogger(__package_name__).getChild(__qualname__)
logger = setup_logger(logger)

def __init__(self, md_format: MDEngineFormat | str = MDEngineFormat.PQ) -> None:
def __init__(
self,
md_format: MDEngineFormat | str = MDEngineFormat.PQ
) -> None:
"""
Parameters
----------
Expand All @@ -46,10 +51,12 @@ def __init__(self, md_format: MDEngineFormat | str = MDEngineFormat.PQ) -> None:
self.md_format = MDEngineFormat(md_format)
self.topology = None

def read(self, frame_string: str,
topology: Topology | None = None,
traj_format: TrajectoryFormat | str = TrajectoryFormat.XYZ
) -> AtomicSystem:
def read(
self,
frame_string: str,
topology: Topology | None = None,
traj_format: TrajectoryFormat | str = TrajectoryFormat.XYZ
) -> AtomicSystem:
"""
Reads a frame from a string.
Expand Down Expand Up @@ -204,10 +211,12 @@ def read_charges(self, frame_string: str) -> AtomicSystem:

return AtomicSystem(topology=topology, charges=charges, cell=cell)

def _check_qmcfc(self,
atoms: List[str],
value: Np1DNumberArray | Np2DNumberArray
) -> Tuple[Np1DNumberArray | Np2DNumberArray, List[str]]:
def _check_qmcfc(
self,
atoms: List[str],
value: Np1DNumberArray | Np2DNumberArray
) -> Tuple[Np1DNumberArray | Np2DNumberArray,
List[str]]:
"""
Check if the first atom is X for QMCFC. If it is, remove it from the list and array.
Expand All @@ -233,8 +242,8 @@ def _check_qmcfc(self,
if atoms[0].upper() != 'X':
self.logger.error(
(
'The first atom in one of the frames is not X. '
'Please use PQ (default) md engine instead'
'The first atom in one of the frames is not X. '
'Please use PQ (default) md engine instead'
),
exception=FrameReaderError
)
Expand All @@ -243,7 +252,11 @@ def _check_qmcfc(self,

return value, atoms

def _get_topology(self, atoms: List[str], topology: Topology | None) -> Topology:
def _get_topology(
self,
atoms: List[str],
topology: Topology | None
) -> Topology:
"""
Returns the topology of the frame.
Expand All @@ -258,21 +271,20 @@ def _get_topology(self, atoms: List[str], topology: Topology | None) -> Topology

topology = Topology(
atoms=[
Atom(atom, disable_type_checking=True)
for atom in atoms
Atom(atom,
disable_type_checking=True) for atom in atoms
]
)

except ElementNotFoundError:

topology = Topology(
atoms=[
Atom(
atom,
use_guess_element=False,
disable_type_checking=True
)
for atom in atoms
Atom(
atom,
use_guess_element=False,
disable_type_checking=True
) for atom in atoms
]
)

Expand Down Expand Up @@ -327,9 +339,9 @@ def _read_header_line(self, header_line: str) -> Tuple[int, Cell]:
return n_atoms, cell

def _read_xyz(self,
splitted_frame_string: List[str],
n_atoms: int
) -> Tuple[Np2DNumberArray, List[str]]:
splitted_frame_string: List[str],
n_atoms: int) -> Tuple[Np2DNumberArray,
List[str]]:
"""
Reads the xyz coordinates and the atom names from the given string.
Expand Down Expand Up @@ -358,22 +370,22 @@ def _read_xyz(self,
atoms = [None] * n_atoms

# Fill xyz and atoms in a single loop
for i, line in enumerate(splitted_frame_string[2:2+n_atoms]):
for i, line in enumerate(splitted_frame_string[2:2 + n_atoms]):
split_line = line.split()
atoms[i] = split_line[0]
xyz[i] = split_line[1:4]

return xyz, atoms
except ValueError as e:
except ValueError:
self.logger.error(
'Invalid file format in xyz coordinates of Frame.',
exception=FrameReaderError
)

def _read_scalar(self,
splitted_frame_string: List[str],
n_atoms: int
) -> Tuple[Np1DNumberArray, List[str]]:
splitted_frame_string: List[str],
n_atoms: int) -> Tuple[Np1DNumberArray,
List[str]]:
"""
Reads the scalar values and the atom names from the given string.
Expand All @@ -400,7 +412,7 @@ def _read_scalar(self,
scalar = np.zeros((n_atoms))
atoms = []
for i in range(n_atoms):
line = splitted_frame_string[2+i]
line = splitted_frame_string[2 + i]

if len(line.split()) != 2:
self.logger.error(
Expand Down
Loading

0 comments on commit 15bbc36

Please sign in to comment.