Adds Extra Parameter to Logs and Updates Version Variable
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
from crystalpol.shared.system.molecule import Molecule
|
||||
from crystalpol.shared.system.crystal import Crystal
|
||||
from crystalpol.shared.system.atom import Atom
|
||||
from crystalpol.shared.config import Config
|
||||
from crystalpol.gaussian import Gaussian
|
||||
|
||||
from typing import List, Tuple
|
||||
from crystalpol.shared.config import Config
|
||||
from crystalpol.shared.system.atom import Atom
|
||||
from crystalpol.shared.system.crystal import Crystal
|
||||
from crystalpol.shared.system.molecule import Molecule
|
||||
from crystalpol.shared.utils.log import Log
|
||||
|
||||
import sys
|
||||
|
||||
from crystalpol.shared.utils.log import Log
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
class Polarization:
|
||||
__slots__ = ('geom_file', 'outfile', 'config', 'gaussian', 'crystal')
|
||||
__slots__ = ("geom_file", "outfile", "config", "gaussian", "crystal")
|
||||
|
||||
def __init__(self, geom_file: str, outfile: str, config: Config) -> None:
|
||||
self.crystal = None
|
||||
@@ -33,21 +31,22 @@ class Polarization:
|
||||
max_charge_diff = sys.float_info.max
|
||||
while max_charge_diff >= self.config.charge_tolerance:
|
||||
|
||||
max_charge_diff, charge_diff = self.update_crystal_charges(
|
||||
max_charge_diff, min_charge_diff, charge_diff = self.update_crystal_charges(
|
||||
self.gaussian.run(cycle, self.crystal),
|
||||
)
|
||||
|
||||
Log.make_run(
|
||||
cycle,
|
||||
max_charge_diff if cycle != 1 else 0,
|
||||
min_charge_diff if cycle != 1 else 0,
|
||||
charge_diff,
|
||||
self.crystal
|
||||
self.crystal,
|
||||
)
|
||||
|
||||
cycle += 1
|
||||
|
||||
def read_crystal(self) -> None:
|
||||
with open(self.geom_file, 'r') as geom_file:
|
||||
with open(self.geom_file, "r") as geom_file:
|
||||
lines = geom_file.readlines()
|
||||
|
||||
molecules = self._get_molecules_from_lines(lines)
|
||||
@@ -57,7 +56,7 @@ class Polarization:
|
||||
for molecule in molecules:
|
||||
self.crystal.add_cell([molecule])
|
||||
|
||||
def update_crystal_charges(self, charges: List[float]) -> Tuple[float, list]:
|
||||
def update_crystal_charges(self, charges: List[float]) -> Tuple[float, float, list]:
|
||||
|
||||
charge_diff = []
|
||||
|
||||
@@ -68,9 +67,12 @@ class Polarization:
|
||||
charge_diff.append(abs(atom.chg - charges[index]))
|
||||
atom.chg = charges[index]
|
||||
|
||||
max_charge_diff = abs(max(charge_diff, key=abs)) if charge_diff else sys.float_info.max
|
||||
max_charge_diff = (
|
||||
abs(max(charge_diff, key=abs)) if charge_diff else sys.float_info.max
|
||||
)
|
||||
min_charge_diff = abs(min(charge_diff, key=abs)) if charge_diff else 0
|
||||
|
||||
return max_charge_diff, charge_diff
|
||||
return max_charge_diff, min_charge_diff, charge_diff
|
||||
|
||||
def _get_molecules_from_lines(self, lines: List[str]) -> List[Molecule]:
|
||||
if (len(lines) % self.config.n_atoms) == 0:
|
||||
@@ -82,7 +84,9 @@ class Polarization:
|
||||
symbol, rx, ry, rz = tuple(atom_line.split())
|
||||
mol.add_atom(
|
||||
Atom(
|
||||
rx, ry, rz,
|
||||
rx,
|
||||
ry,
|
||||
rz,
|
||||
symbol=symbol.ljust(2),
|
||||
)
|
||||
)
|
||||
@@ -105,4 +109,4 @@ class Polarization:
|
||||
@staticmethod
|
||||
def split(array: List, partitions: int):
|
||||
for i in range(0, len(array), partitions):
|
||||
yield array[i: i + partitions]
|
||||
yield array[i : i + partitions]
|
||||
|
||||
Reference in New Issue
Block a user