Skip to content
Merged
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
41 changes: 9 additions & 32 deletions ThermoScreening/thermo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,9 @@ def read_coord(coord_file: str, engine: str):
if coord_file.endswith(".gen"):
data_N, data_atoms, data_xyz, cell_vectors, pbc = read_gen(coord_file)
return data_N, data_atoms, data_xyz, cell_vectors, pbc
logger.error(
"The input file is not supported.",
exception=TSNotImplementedError
)
raise TSNotImplementedError("The input file is not supported.")

else:
logger.error(
"The engine is not supported.",
exception=TSNotImplementedError
)
raise TSNotImplementedError("The engine is not supported.")


def read_vibrational(vibrational_file: str, engine: str):
Expand Down Expand Up @@ -223,10 +216,7 @@ def read_vibrational(vibrational_file: str, engine: str):
vibrational_frequencies = read_vib_file(vibrational_file)
else:
# throw error
logger.error(
"The engine is not supported.",
exception=TSNotImplementedError
)
raise TSNotImplementedError("The engine is not supported.")

return vibrational_frequencies

Expand All @@ -252,10 +242,7 @@ def unit_length(engine: str):
"""
if engine == "dftb+":
return "Angstrom"
logger.error(
"The engine is not supported.",
exception=TSNotImplementedError
)
raise TSNotImplementedError("The engine is not supported.")


def unit_energy(engine: str):
Expand All @@ -279,10 +266,7 @@ def unit_energy(engine: str):
"""
if engine == "dftb+":
return "Hartree"
logger.error(
"The engine is not supported.",
exception=TSNotImplementedError
)
raise TSNotImplementedError("The engine is not supported.")


def unit_mass(engine: str):
Expand All @@ -306,10 +290,7 @@ def unit_mass(engine: str):
"""
if engine == "dftb+":
return "amu"
logger.error(
"The engine is not supported.",
exception=TSNotImplementedError
)
raise TSNotImplementedError("The engine is not supported.")


def unit_frequency(engine: str):
Expand All @@ -333,10 +314,7 @@ def unit_frequency(engine: str):
"""
if engine == "dftb+":
return "cm^-1"
logger.error(
"The engine is not supported.",
exception=TSNotImplementedError
)
raise TSNotImplementedError("The engine is not supported.")


def _atoms_from_ase(atoms):
Expand Down Expand Up @@ -416,9 +394,8 @@ def run_thermo(

expected_dof = dof(atom_list)
if len(vibrational_frequencies) < expected_dof:
logger.error(
"The number of vibrational frequencies does not match with the degree of freedom.",
exception=TSValueError
raise TSValueError(
"The number of vibrational frequencies does not match with the degree of freedom."
)

system_info = System(
Expand Down
48 changes: 10 additions & 38 deletions ThermoScreening/thermo/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,54 +81,35 @@ def __init__(
"""

if symbol is None and number is None:
self.logger.error(
"Either symbol or number has to be given to initialize the atom.",
exception=TSValueError
)
raise TSValueError("Either symbol or number has to be given to initialize the atom.")

if symbol is not None and number is not None:
if number != atomicNumbers[symbol.lower()]:
self.logger.error(
"The symbol and atomic number are not consistent.",
exception=TSValueError
)
raise TSValueError("The symbol and atomic number are not consistent.")
if number is not None:
self._number = number
try:
self._symbol = atomic_Symbol[int(number)].capitalize()
except:
self.logger.error(
f"The atomic number {number} is not known.",
exception=TSValueError
)
raise TSValueError(f"The atomic number {number} is not known.") from None
self._mass = atomicMasses[self._symbol.lower()]
self._configuration = atomicElectronConfigurations[self._symbol.lower()]
else:
self._symbol = symbol
try:
self._number = atomicNumbers[symbol.lower()]
except:
self.logger.error(
f"The chemical symbol {symbol} is not known.",
exception=TSValueError
)
raise TSValueError(f"The chemical symbol {symbol} is not known.") from None
self._mass = atomicMasses[symbol.lower()]
self._configuration = atomicElectronConfigurations[symbol.lower()]

if position is None:
self.logger.error(
"The position of the atom has to be given to initialize the atom.",
exception=TSValueError
)
raise TSValueError("The position of the atom has to be given to initialize the atom.")

else:
self._position = position
self._position = position

if len(position) != 3:
self.logger.error(
"The position of the atom has to be a 3D vector.",
exception=TSValueError
)
raise TSValueError("The position of the atom has to be a 3D vector.")

@property
def symbol(self):
Expand Down Expand Up @@ -194,10 +175,7 @@ def position(self, array):
If the length of the position is not 3.
"""
if len(array) != 3:
self.logger.error(
"The position of the atom has to be a 3D vector.",
exception=TSValueError
)
raise TSValueError("The position of the atom has to be a 3D vector.")
self._position = array

def change_atom(
Expand Down Expand Up @@ -226,10 +204,7 @@ def change_atom(
try:
self._number = atomicNumbers[self._symbol.lower()]
except:
self.logger.error(
f"The chemical symbol {symbol} is not known.",
exception=TSValueError
)
raise TSValueError(f"The chemical symbol {symbol} is not known.") from None

self._mass = atomicMasses[symbol.lower()]
self._configuration = atomicElectronConfigurations[symbol.lower()]
Expand All @@ -239,10 +214,7 @@ def change_atom(
try:
self._symbol = atomic_Symbol[int(number)].capitalize()
except:
self.logger.error(
f"The atomic number {number} is not known.",
exception=TSValueError
)
raise TSValueError(f"The atomic number {number} is not known.") from None
self._mass = atomicMasses[self._symbol.lower()]
self._configuration = atomicElectronConfigurations[self._symbol.lower()]
if position is not None:
Expand Down
20 changes: 4 additions & 16 deletions ThermoScreening/thermo/inputFileReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def __init__(
None
"""
if input_file is None:
self.logger.error(
"The input file has to be given to initialize the InputFileReader.",
exception=TSValueError,
)
raise TSValueError("The input file has to be given to initialize the InputFileReader.")
self._input_file = input_file
self._read()
self._check()
Expand All @@ -78,10 +75,7 @@ def _read(self):
if not line or line.startswith("#"):
continue
if "=" not in line:
self.logger.error(
f"The line '{line}' is not a valid key-value assignment.",
exception=TSValueError,
)
raise TSValueError(f"The line '{line}' is not a valid key-value assignment.")
key, value = line.split("=", maxsplit=1)
self._dictionary[key.strip()] = value.strip()

Expand Down Expand Up @@ -118,10 +112,7 @@ def _check_required_keys(self):
"""
for key in self.required_keys:
if key not in self._dictionary.keys():
self.logger.error(
f"The key {key} is not set in the input file.",
exception=TSValueError
)
raise TSValueError(f"The key {key} is not set in the input file.")


def _check_known_keys(self):
Expand All @@ -139,8 +130,5 @@ def _check_known_keys(self):
"""
for key in self._dictionary.keys():
if key not in self.required_keys:
self.logger.error(
f"The key {key} is not known.",
exception=TSValueError
)
raise TSValueError(f"The key {key} is not known.")

37 changes: 9 additions & 28 deletions ThermoScreening/thermo/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ def linearity(atoms: List[Atom]) -> bool:
If the number of atoms is 1.
"""
if len(atoms) == 1:
System.logger.error(
"Number of atoms must be greater than 1. The system is monoatomic.",
exception=TSValueError
)
elif len(atoms) == 2:
raise TSValueError("Number of atoms must be greater than 1. The system is monoatomic.")
if len(atoms) == 2:
return True

masses = np.array([atom.mass for atom in atoms], dtype=float)
Expand Down Expand Up @@ -172,9 +169,8 @@ def dimensionality(atoms: List[Atom]) -> int:
and np.array_equal(y, zero_array)
and np.array_equal(x, zero_array)
):
ValueError("The system is 0D!")
else:
return 3
raise TSValueError("The system is 0D!") # pragma: no cover
return 3


def dim(atoms: List[Atom]) -> int:
Expand All @@ -201,10 +197,7 @@ def dim(atoms: List[Atom]) -> int:
return 1
if number_of_atoms > 1:
return dimensionality(atoms)
System.logger.error(
"The number of atoms must be greater than 0.",
exception=TSValueError
)
raise TSValueError("The number of atoms must be greater than 0.")


def dof(atoms: List[Atom]) -> int:
Expand Down Expand Up @@ -234,10 +227,7 @@ def dof(atoms: List[Atom]) -> int:
return (
(3 * number_of_atoms - 5) if linearity(atoms) else (3 * number_of_atoms - 6)
)
System.logger.error(
"The number of atoms must be greater than 0.",
exception=TSValueError
)
raise TSValueError("The number of atoms must be greater than 0.")


def spin(charge: float) -> float:
Expand Down Expand Up @@ -628,22 +618,13 @@ def __init__(
"""

if atoms is None:
self.logger.error(
"Atoms must be provided.",
exception=TSValueError
)
raise TSValueError("Atoms must be provided.")

if len(atoms) == 0:
self.logger.error(
"The number of atoms must be greater than 0.",
exception=TSValueError
)
raise TSValueError("The number of atoms must be greater than 0.")

if vibrational_frequencies is None:
self.logger.error(
"Vibrational frequencies must be provided.",
exception=TSValueError
)
raise TSValueError("Vibrational frequencies must be provided.")

self._atoms = atoms
self._charge = charge
Expand Down
Loading
Loading