Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
97gamjak committed Nov 12, 2023
2 parents b2c339c + 55ad208 commit ebf2a55
Show file tree
Hide file tree
Showing 20 changed files with 977 additions and 321 deletions.
4 changes: 1 addition & 3 deletions PQAnalysis/core/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
"""

import numpy as np

from multimethod import multimethod
from beartype.typing import Any, Tuple
from numbers import Real

from PQAnalysis.utils.exceptions import ElementNotFoundError
from PQAnalysis.exceptions import ElementNotFoundError


def guess_element(id: int | str) -> Tuple[str, int, Real]:
Expand Down
2 changes: 1 addition & 1 deletion PQAnalysis/core/atomicSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from .atom import Atom
from .cell import Cell
from ..utils.mytypes import Numpy2DFloatArray, Numpy1DFloatArray
from ..types import Numpy2DFloatArray, Numpy1DFloatArray


def check_atoms_pos(func):
Expand Down
2 changes: 1 addition & 1 deletion PQAnalysis/core/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from beartype.typing import Any
from numbers import Real

from ..utils.mytypes import Numpy3x3FloatArray, Numpy2DFloatArray, Numpy1DFloatArray
from ..types import Numpy3x3FloatArray, Numpy2DFloatArray, Numpy1DFloatArray


class Cell:
Expand Down
70 changes: 70 additions & 0 deletions PQAnalysis/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
A module containing different exceptions which could be useful.
...
Classes
-------
PQException
Base class for exceptions in this module.
ElementNotFoundError
Exception raised if the given element id is not valid
TrajectoryFormatError
Exception raised if the given enum is not valid
"""

from beartype.typing import Any


class PQException(Exception):
"""
Base class for exceptions in this module.
"""

def __init__(self, message: str) -> None:
self.message = message
super().__init__(self.message)


class ElementNotFoundError(PQException):
"""
Exception raised if the given element id is not valid
"""

def __init__(self, id: Any) -> None:
self.id = id
self.message = f"""Id {self.id} is not a valid element identifier."""
super().__init__(self.message)


class FormatEnumError(PQException):
"""
Exception raised if the given enum is not valid
"""

def __init__(self, value: object, enum: object) -> None:
self.enum = enum
self.value = value
self.message = f"""
'{self.value}' is not a valid {enum.__name__}.
Possible values are: {enum.member_repr()}
or their case insensitive string representation: {enum.value_repr()}"""
super().__init__(self.message)


class TrajectoryFormatError(FormatEnumError):
"""
Exception raised if the given enum is not valid
"""

def __init__(self, value: object, enum: object) -> None:
super().__init__(value, enum)


class MDEngineFormatError(FormatEnumError):
"""
Exception raised if the given enum is not valid
"""

def __init__(self, value: object, enum: object) -> None:
super().__init__(value, enum)
22 changes: 7 additions & 15 deletions PQAnalysis/io/energyFileReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .base import BaseReader
from .infoFileReader import InfoFileReader
from ..physicalData.energy import Energy
from ..traj.formats import MDEngineFormat


class EnergyFileReader(BaseReader):
Expand All @@ -34,15 +35,15 @@ class EnergyFileReader(BaseReader):
The name of the info file to read from.
withInfoFile : bool
If True, the info file was found.
format : MDEngineFormat
The format of the file. Default is MDEngineFormat.PIMD_QMCF.
"""

formats = ["pimd-qmcf", "qmcfc"]

def __init__(self,
filename: str,
info_filename: str | None = None,
use_info_file: bool = True,
format: str = "pimd-qmcf"
format: MDEngineFormat | str = MDEngineFormat.PIMD_QMCF
) -> None:
"""
Initializes the EnergyFileReader with the given filename.
Expand All @@ -61,13 +62,8 @@ def __init__(self,
The name of the info file to read from, by default None
use_info_file : bool, optional
If True, the info file is searched for, by default True
format : str, optional
The format of the info file, by default "pimd-qmcf"
Raises
------
ValueError
If the format is not supported.
format : MDEngineFormat | str, optional
The format of the file, by default MDEngineFormat.PIMD_QMCF
"""
super().__init__(filename)
self.info_filename = info_filename
Expand All @@ -77,11 +73,7 @@ def __init__(self,
else:
self.withInfoFile = False

if format not in self.formats:
raise ValueError(
f"Format {format} is not supported. Supported formats are {self.formats}.")

self.format = format
self.format = MDEngineFormat(format)

def read(self) -> Energy:
"""
Expand Down
Loading

0 comments on commit ebf2a55

Please sign in to comment.