SetGlobas/MolHandling(fixes)/DicePlayer Translation

Fixed Numerus functions in the SetGlobals file and MolHandling, translated DicePlayer and tested till, such as inertia_tensor, add_type, center_of_mass_to_origin. standard_orientation; and removed chglevel keyword

Signed-off-by: Vitor Hideyoshi <vitor.h.n.batista@gmail.com>
This commit is contained in:
2021-10-24 00:55:11 -03:00
committed by Vitor Hideyoshi
parent 316acf4761
commit 6017f272b3
5 changed files with 64 additions and 77 deletions

View File

@@ -28,7 +28,7 @@ class System:
def add_type(self,nmols, m):
self.molecule.append(m)
self.nmols = nmols
self.nmols.append(nmols)
# Função que calcula a distância entre dois centros de massa
# e por se tratar de uma função de dois atomos não deve ser
@@ -208,21 +208,17 @@ class Molecule:
def center_of_mass(self):
com = np.zeros(3)
total_mass = 0.0
self.com = np.zeros(3)
for atom in self.atom:
total_mass += atom.mass
com += atom.mass * np.array([atom.rx, atom.ry, atom.rz])
self.com += atom.mass * np.array([atom.rx, atom.ry, atom.rz])
com = com / total_mass
self.com = com
self.com = self.com / self.total_mass
def center_of_mass_to_origin(self):
com = self.center_of_mass()
self.center_of_mass()
for atom in self.atom:
@@ -260,6 +256,30 @@ class Molecule:
return np.array(distances).reshape(dim, dim)
def inertia_tensor(self):
self.center_of_mass()
Ixx = Ixy = Ixz = Iyy = Iyz = Izz = 0.0
for atom in self.atom:
#### Obtain the displacement from the center of mass
dx = atom.rx - self.com[0]
dy = atom.ry - self.com[1]
dz = atom.rz - self.com[2]
#### Update the diagonal components of the tensor
Ixx += atom.mass * (dy**2 + dz**2)
Iyy += atom.mass * (dz**2 + dx**2)
Izz += atom.mass * (dx**2 + dy**2)
#### Update the off-diagonal components of the tensor
Ixy += atom.mass * dx * dy * -1
Ixz += atom.mass * dx * dz * -1
Iyz += atom.mass * dy * dz * -1
return np.array([[Ixx, Ixy, Ixz],
[Ixy, Iyy, Iyz],
[Ixz, Iyz, Izz]])
def eixos(self):
eixos = np.zeros(3)
@@ -288,36 +308,13 @@ class Molecule:
return eixos
def inertia_tensor(self):
Ixx = Ixy = Ixz = Iyy = Iyz = Izz = 0.0
for atom in self.atom:
#### Obtain the displacement from the center of mass
dx = atom.rx - self.com[0]
dy = atom.ry - self.com[1]
dz = atom.rz - self.com[2]
#### Update the diagonal components of the tensor
Ixx += atom.mass * (dy**2 + dz**2)
Iyy += atom.mass * (dz**2 + dx**2)
Izz += atom.mass * (dx**2 + dy**2)
#### Update the off-diagonal components of the tensor
Ixy += atom.mass * dx * dy * -1
Ixz += atom.mass * dx * dz * -1
Iyz += atom.mass * dy * dz * -1
return np.array([ [Ixx, Ixy, Ixz],
[Ixy, Iyy, Iyz],
[Ixz, Iyz, Izz] ])
def principal_axes(self):
try:
evals, evecs = linalg.eigh(self.inertia_tensor())
except:
sys.exit("Error: diagonalization of inertia tensor did not converge")
return evals, evecs
def read_position(self):
@@ -366,7 +363,6 @@ class Molecule:
def standard_orientation(self):
self.center_of_mass_to_origin()
tensor = self.inertia_tensor()
evals, evecs = self.principal_axes()
if round(linalg.det(evecs)) == -1:
@@ -435,6 +431,4 @@ class Atom:
self.chg = chg # Double
self.eps = eps # Double
self.sig = sig # Double
self.mass = atommass[self.na] # Double
self.mass = atommass[self.na] # Double

View File

@@ -1,6 +1,7 @@
import os, sys
import shutil
import textwrap
import types
from DPpack.MolHandling import *
from DPpack.PTable import *
@@ -179,8 +180,8 @@ class Internal:
except ValueError:
sys.exit(err)
elif key in ('level', 'chglevel'):
setattr(self.gaussian, key, value[0])
elif key == 'level':
setattr(self.gaussian, key, value)
elif key in ('gmiddle', 'gbottom'):
setattr(self.gaussian, key, value[0])
@@ -243,9 +244,6 @@ class Internal:
if self.gaussian.pop != "chelpg" and (self.player.ghosts == "yes" or self.player.lps == "yes"):
sys.exit("Error: ghost atoms or lone pairs only available with 'pop = chelpg')")
if self.gaussian.chglevel == None:
self.gaussian.chglevel = self.gaussian.level
## Check only if QM program is Molcas:
# if self.player.qmprog == "molcas":
@@ -636,7 +634,7 @@ class Internal:
pass
### I still have to talk with Herbet about
def populate_asec_vdw(self, cycle):
asec_charges = [] # (rx, ry, rz, chg)
@@ -651,17 +649,17 @@ class Internal:
nsitesref = len(self.system.molecule[0]) + len(ghost_atoms) + len(lp_atoms)
nsites_total = dice['nmol'][0] * nsitesref
for i in range(1, len(dice['nmol'])):
nsites_total += dice['nmol'][i] * len(molecules[i])
nsites_total = self.dice.nmol[0] * nsitesref
for i in range(1, len(self.dice.nmol)):
nsites_total += self.dice.nmol[i] * len(self.system.molecule[i])
thickness = []
picked_mols = []
for proc in range(1, player['nprocs'] + 1): ## Run over folders
for proc in range(1, self.player.nprocs + 1): ## Run over folders
path = "step{:02d}".format(cycle) + os.sep + "p{:02d}".format(proc)
file = path + os.sep + dice['outname'] + ".xyz"
file = path + os.sep + self.dice.outname + ".xyz"
if not os.path.isfile(file):
sys.exit("Error: cannot find file {}".format(file))
try:
@@ -677,23 +675,23 @@ class Internal:
box = xyzfile.pop(0).split()[-3:]
box = [ float(box[0]), float(box[1]), float(box[2]) ]
sizes = sizes_of_molecule(molecules[0])
sizes = self.system.molecule[0].sizes_of_molecule()
thickness.append( min([ (box[0] - sizes[0])/2, (box[1] - sizes[1])/2,
(box[2] - sizes[2])/2 ]) )
xyzfile = xyzfile[nsitesref:] ## Skip the first (reference) molecule
mol_count = 0
for type in range(len(dice['nmol'])): ## Run over types of molecules
for type in range(len(self.dice.nmol)): ## Run over types of molecules
if type == 0:
nmols = dice['nmol'][0] - 1
nmols = self.dice.nmol[0] - 1
else:
nmols = dice['nmol'][type]
nmols = self.dice.nmol[type]
for mol in range(nmols): ## Run over molecules of each type
new_molecule = []
for site in range(len(molecules[type])): ## Run over sites of each molecule
for site in range(len(self.system.molecule[types].atoms)): ## Run over sites of each molecule
new_molecule.append({})
line = xyzfile.pop(0).split()
@@ -831,8 +829,6 @@ class Internal:
self.gmiddle = None # In each case, if a filename is given, its content will be
self.gbottom = None # inserted in the gaussian input
self.pop = "chelpg"
self.chglevel = None
self.level = None
# class Molcas: