diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 52e1068..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.pythonPath": "/home/hideyoshi/Python/3.8/bin/python3.8" -} \ No newline at end of file diff --git a/control.yml b/control.yml.exemple similarity index 75% rename from control.yml rename to control.yml.exemple index 5d14715..3b70e88 100644 --- a/control.yml +++ b/control.yml.exemple @@ -11,12 +11,13 @@ dice: ncores: 3 nmol: [1, 50] dens: 0.75 - nstep: [4000, 6000] + nstep: [2000, 3000] isave: 1000 ljname: 'phb.ljc' outname: 'phb' - randominit: 'first' + randominit: 'always' gaussian: + qmprog: 'g16' level: 'MP2/aug-cc-pVDZ' - keywords: 'freq=intmodes' \ No newline at end of file + keywords: 'freq' \ No newline at end of file diff --git a/diceplayer/DPpack/Environment/Molecule.py b/diceplayer/DPpack/Environment/Molecule.py index 9f5c3bb..4269211 100644 --- a/diceplayer/DPpack/Environment/Molecule.py +++ b/diceplayer/DPpack/Environment/Molecule.py @@ -31,7 +31,7 @@ class Molecule: energy (NDArray[Any, Any]): The energy of the represented molecule gradient (NDArray[Any, Any]): The first derivative of the energy relative to the position hessian (NDArray[Any, Any]): The second derivative of the energy relative to the position - totalMass (int): The total mass of the molecule + total_mass (int): The total mass of the molecule com (NDArray[Any, Any]): The center of mass of the molecule """ @@ -50,7 +50,10 @@ class Molecule: self.gradient: NDArray[Any, Any] self.hessian: NDArray[Any, Any] - self.totalMass: int = 0 + self.ghost_atoms: List[Atom] = [] + self.lp_atoms: List[Atom] = [] + + self.total_mass: int = 0 self.com: NDArray[Any, Any] = None def add_atom(self, a: Atom) -> None: diff --git a/diceplayer/DPpack/External/Dice.py b/diceplayer/DPpack/External/Dice.py index cbf570a..5b477f8 100644 --- a/diceplayer/DPpack/External/Dice.py +++ b/diceplayer/DPpack/External/Dice.py @@ -27,7 +27,6 @@ class Dice: nprocs: int = None randominit = "first" combrule = "*" - ncores = 1 temp = 300.0 press = 1.0 @@ -35,8 +34,8 @@ class Dice: dens = None ljname = None outname = None - nmol: List[int] = [] - nstep: List[int] = [] + nmol: List[int] = None + nstep: List[int] = None upbuf = 360 def __init__(self, infile: TextIO, outfile: TextIO) -> None: @@ -46,7 +45,7 @@ class Dice: @NotNull(requiredArgs=["ncores", "nmol", "dens", "nstep", "ljname", "outname"]) def updateKeywords(self, **data): - self.__dict__.update(data) + self.__dict__.update(**data) def __new_density(self, cycle: int, proc: int) -> float: diff --git a/diceplayer/DPpack/External/Gaussian.py b/diceplayer/DPpack/External/Gaussian.py index d589197..4062342 100644 --- a/diceplayer/DPpack/External/Gaussian.py +++ b/diceplayer/DPpack/External/Gaussian.py @@ -17,21 +17,18 @@ from diceplayer.DPpack.Utils.Validations import NotNull class Gaussian: - qmprog = "g09" mem = None - keywords = None chgmult = [0, 1] gmiddle = None # In each case, if a filename is given, its content will be gbottom = None # inserted in the gaussian input pop = "chelpg" - level = None def __init__(self) -> None: pass - @NotNull(requiredArgs=["level"]) + @NotNull(requiredArgs=["qmprog","level"]) def updateKeywords(self, **data): - self.__dict__.update(data) + self.__dict__.update(**data) def run_formchk(self, cycle: int, fh: TextIO): diff --git a/diceplayer/DPpack/Player.py b/diceplayer/DPpack/Player.py index 106a9e4..f6a93a5 100644 --- a/diceplayer/DPpack/Player.py +++ b/diceplayer/DPpack/Player.py @@ -21,22 +21,32 @@ env = ["OMP_STACKSIZE"] class Player: + + maxcyc = None + opt = None + nprocs = None + qmprog = None + lps = None + ghosts = None + altsteps = None + + combrule = None + + TOL_RMS_FORCE = 3e-4 + TOL_MAX_FORCE = 4.5e-4 + TOL_RMS_STEP = 1.2e-3 + TOL_MAX_SET = 1.8e-3 + TRUST_RADIUS = None + + continued: bool = False + def __init__(self, infile: TextIO, outfile: TextIO) -> None: self.infile = infile self.outfile = outfile - self.continued: bool = None - self.system = System() - self.player = self.Player() - self.player_keywords = [ - a - for a in dir(self.player) - if not a.startswith("__") and not callable(getattr(self.player, a)) - ] - self.dice = Dice(infile, outfile) self.dice_keywords = [ a @@ -51,28 +61,20 @@ class Player: if not a.startswith("__") and not callable(getattr(self.gaussian, a)) ] - self.TOL_RMS_FORCE = 3e-4 - self.TOL_MAX_FORCE = 4.5e-4 - self.TOL_RMS_STEP = 1.2e-3 - self.TOL_MAX_SET = 1.8e-3 - self.TRUST_RADIUS = None - - self.combrule = None - @NotNull( requiredArgs=["maxcyc", "opt", "nprocs", "qmprog", "lps", "ghosts", "altsteps"] ) def updateKeywords(self, **data): - self.__dict__.update(data) + self.__dict__.update(**data) def read_keywords(self) -> None: with self.infile as f: data = yaml.load(f, Loader=yaml.SafeLoader) - self.updateKeywords(data.get("diceplayer")) - self.dice.updateKeywords(data.get("dice")) - self.gaussian.updateKeywords(data.get("gaussian")) + self.updateKeywords(**data.get("diceplayer")) + self.dice.updateKeywords(**data.get("dice")) + self.gaussian.updateKeywords(**data.get("gaussian")) def check_keywords(self) -> None: @@ -108,7 +110,7 @@ class Player: ) # Check only if QM program is Gaussian: - if self.player.qmprog in ("g03", "g09", "g16"): + if self.qmprog in ("g03", "g09", "g16"): if self.gaussian.level == None: sys.exit( @@ -126,14 +128,14 @@ class Player: sys.exit("Error: file {} not found".format(self.gaussian.gbottom)) if self.gaussian.pop != "chelpg" and ( - self.player.ghosts == "yes" or self.player.lps == "yes" + self.ghosts == "yes" or self.lps == "yes" ): sys.exit( "Error: ghost atoms or lone pairs only available with 'pop = chelpg')" ) # Check only if QM program is Molcas: - # if self.player.qmprog == "molcas": + # if self.qmprog == "molcas": # if self.molcas.mbottom == None: # sys.exit("Error: 'mbottom' keyword not specified in file {}".format(self.infile)) @@ -144,7 +146,7 @@ class Player: # if self.molcas.basis == None: # sys.exit("Error: 'basis' keyword not specified in file {}".format(self.infile)) - if self.player.altsteps != 0: + if self.altsteps != 0: # Verifica se tem mais de 1 molecula QM # (No futuro usar o RMSD fit para poder substituir todas as moleculas QM @@ -155,9 +157,9 @@ class Player: ) # if not zero, altsteps cannot be less than min_steps - self.player.altsteps = max(min_steps, self.player.altsteps) + self.altsteps = max(min_steps, self.altsteps) # altsteps value is always the nearest multiple of 1000 - self.player.altsteps = round(self.player.altsteps / 1000) * 1000 + self.altsteps = round(self.altsteps / 1000) * 1000 for i in range(len(self.dice.nstep)): # nstep can never be less than min_steps @@ -198,16 +200,6 @@ class Player: "\n" ) - for key in sorted(self.player_keywords): - if getattr(self.player, key) != None: - if isinstance(getattr(self.player, key), list): - string = " ".join(str(x) for x in getattr(self.player, key)) - self.outfile.write("{} = {}\n".format(key, string)) - else: - self.outfile.write( - "{} = {}\n".format(key, getattr(self.player, key)) - ) - self.outfile.write("\n") self.outfile.write( @@ -227,7 +219,7 @@ class Player: self.outfile.write("\n") - if self.player.qmprog in ("g03", "g09", "g16"): + if self.qmprog in ("g03", "g09", "g16"): self.outfile.write( "------------------------------------------------------------------------------------------\n" @@ -248,7 +240,7 @@ class Player: self.outfile.write("\n") - # elif self.player.qmprog == "molcas": + # elif self.qmprog == "molcas": # self.outfile.write("------------------------------------------------------------------------------------------\n" # " MOLCAS variables being used in this run:\n" @@ -492,7 +484,7 @@ class Player: self.outfile.write("\n") - if self.player.ghosts == "yes" or self.player.lps == "yes": + if self.ghosts == "yes" or self.lps == "yes": self.outfile.write( "\n" "------------------------------------------------------------------------------------------\n" @@ -585,11 +577,11 @@ class Player: self.dice.configure( StepDTO( - self.player.initcyc, - self.player.nprocs, - self.player.altsteps, - self.system.nmols, - self.system.molecule, + initcyc=self.initcyc, + nprocs=self.nprocs, + altsteps=self.altsteps, + nmol=self.system.nmols, + molecule=self.system.molecule, ) ) @@ -600,17 +592,17 @@ class Player: def gaussian_start(self, cycle: int, geomsfh: TextIO): self.gaussian.configure( - self.player.initcyc, - self.player.nprocs, + self.initcyc, + self.nprocs, self.dice.ncores, - self.player.altsteps, - self.player.switchcyc, - self.player.opt, + self.altsteps, + self.switchcyc, + self.opt, self.system.nmols, self.system.molecule, ) - position = self.gaussian.start(cycle, self.outfile, self.player.readhessian) + position = self.gaussian.start(cycle, self.outfile, self.readhessian) ## Update the geometry of the reference molecule self.system.update_molecule(position, self.outfile) @@ -637,7 +629,7 @@ class Player: else: nconfigs = int(self.dice.nstep[-1] / self.dice.isave) - norm_factor = nconfigs * self.player.nprocs + norm_factor = nconfigs * self.nprocs nsitesref = len(self.system.molecule[0].atom) # nsitesref = ( @@ -653,7 +645,7 @@ class Player: thickness = [] picked_mols = [] - for proc in range(1, self.player.nprocs + 1): # Run over folders + for proc in range(1, self.nprocs + 1): # Run over folders simdir = "simfiles" path = ( @@ -748,7 +740,7 @@ class Player: asec_charges[-1]["rz"] = atom.rz asec_charges[-1]["chg"] = atom.chg / norm_factor - # if self.player.vdwforces == "yes": + # if self.vdwforces == "yes": # vdw_meanfield[-1]["rx"] = atom["rx"] # vdw_meanfield[-1]["ry"] = atom["ry"] # vdw_meanfield[-1]["rz"] = atom["rz"] @@ -809,23 +801,4 @@ class Player: ) otherfh.close() - return asec_charges - - class Player: - def __init__(self) -> None: - - self.maxcyc = None - self.nprocs = 1 - self.switchcyc = 3 - self.altsteps = 20000 - self.maxstep = 0.3 - self.opt = "yes" - self.freq = "no" - self.readhessian = "no" - self.lps = "no" - self.ghosts = "no" - self.vdwforces = "no" - self.tol_factor = 1.2 - self.qmprog = "g16" - - self.initcyc = 1 + return asec_charges \ No newline at end of file diff --git a/diceplayer/DPpack/Utils/StepDTO.py b/diceplayer/DPpack/Utils/StepDTO.py index 255a997..99c01ae 100644 --- a/diceplayer/DPpack/Utils/StepDTO.py +++ b/diceplayer/DPpack/Utils/StepDTO.py @@ -7,11 +7,12 @@ from diceplayer.DPpack.Environment.Molecule import Molecule @dataclass class StepDTO: - initcyc: int - nprocs: int - ncores: int - altsteps: int - switchcyc: int - opt: str - nmol: List[int] - molecule: List[Molecule] \ No newline at end of file + cycle: int = None + initcyc: int = None + nprocs: int = None + ncores: int = None + altsteps: int = None + switchcyc: int = None + opt: str = None + nmol: List[int] = None + molecule: List[Molecule] = None \ No newline at end of file diff --git a/diceplayer/__main__.py b/diceplayer/__main__.py index e97041f..bff71a8 100644 --- a/diceplayer/__main__.py +++ b/diceplayer/__main__.py @@ -4,21 +4,15 @@ import argparse import os import pickle import shutil -import signal import sys -import time -from multiprocessing import Process, connection -import numpy as np import setproctitle -from diceplayer.DPpack.Environment.Atom import Atom -from diceplayer.DPpack.Environment.Molecule import Molecule from diceplayer.DPpack.Player import Player from diceplayer.DPpack.Utils.Misc import * -__version = "dev" -setproctitle.setproctitle("diceplayer-{}".format(__version)) +__VERSION = "dev" +setproctitle.setproctitle("diceplayer-{}".format(__VERSION)) if __name__ == "__main__": #### Read and store the arguments passed to the program #### @@ -29,12 +23,12 @@ if __name__ == "__main__": "--continue", dest="opt_continue", default=False, action="store_true" ) parser.add_argument( - "--version", action="version", version="diceplayer-" + __version + "--version", action="version", version="diceplayer-" + __VERSION ) parser.add_argument( "-i", dest="infile", - default="control.in", + default="control.yml", metavar="INFILE", help="input file of diceplayer [default = control.in]", ) @@ -90,9 +84,10 @@ if __name__ == "__main__": player.print_keywords() if args.opt_continue: - player.player.initcyc = save[0] + 1 + player.initcyc = save[0] + 1 player.system = save[1] else: + player.initcyc = 1 player.read_potential() #### Check whether the executables are in the path @@ -126,13 +121,13 @@ if __name__ == "__main__": make_simulation_dir() else: simdir = "simfiles" - stepdir = "step{:02d}".format(player.player.initcyc) + stepdir = "step{:02d}".format(player.initcyc) if os.path.exists(simdir + os.sep + stepdir): shutil.rmtree(simdir + os.sep + stepdir) #### Open the geoms.xyz file and prints the initial geometry if starting from zero - if player.player.initcyc == 1: + if player.initcyc == 1: try: path = "geoms.xyz" geomsfh = open(path, "w", 1) @@ -153,8 +148,8 @@ if __name__ == "__main__": position = player.system.molecule[0].read_position() ## If restarting, read the last gradient and hessian - # if player.player.initcyc > 1: - # if player.player.qmprog in ("g03", "g09", "g16"): + # if player.initcyc > 1: + # if player.qmprog in ("g03", "g09", "g16"): # Gaussian.read_forces("grad_hessian.dat") # Gaussian.read_hessian_fchk("grad_hessian.dat") @@ -168,9 +163,7 @@ if __name__ == "__main__": player.outfile.write("\n" + 90 * "-" + "\n") - for cycle in range( - player.player.initcyc, player.player.initcyc + player.player.maxcyc - ): + for cycle in range(player.initcyc, player.initcyc + player.maxcyc): player.outfile.write("{} Step # {}\n".format(40 * " ", cycle)) player.outfile.write(90 * "-" + "\n\n") @@ -192,7 +185,7 @@ if __name__ == "__main__": asec_charges = player.populate_asec_vdw(cycle) ## After ASEC is built, compress files bigger than 1MB - for proc in range(1, player.player.nprocs + 1): + for proc in range(1, player.nprocs + 1): path = "step{:02d}".format(cycle) + os.sep + "p{:02d}".format(proc) compress_files_1mb(path) diff --git a/geoms.xyz b/geoms.xyz deleted file mode 100644 index d2cf318..0000000 --- a/geoms.xyz +++ /dev/null @@ -1,15 +0,0 @@ -Cycle # 0 -Number of site: 12 -C 1.400000 0.000000 0.000000 -C 0.700000 1.212436 0.000000 -C -0.700000 1.212436 0.000000 -C -1.400000 0.000000 0.000000 -C -0.700000 -1.212436 0.000000 -C 0.700000 -1.212436 0.000000 -H 2.488100 0.000000 0.000000 -H 1.244000 2.154671 0.000000 -H -1.244000 2.154671 0.000000 -H -2.488100 0.000000 0.000000 -H -1.244000 -2.154671 0.000000 -H 1.244000 -2.154671 0.000000 ----------------------------------------- diff --git a/phb.ljc b/phb.ljc.exemple similarity index 60% rename from phb.ljc rename to phb.ljc.exemple index 597371e..04f2794 100644 --- a/phb.ljc +++ b/phb.ljc.exemple @@ -1,18 +1,18 @@ * 2 12 BENZENO - 1 6 0.000000 1.400000 0.000000 0.00000000 0.1100 3.7500 - 1 6 1.212436 0.700000 0.000000 0.00000000 0.1100 3.7500 - 1 6 1.212436 -0.700000 0.000000 0.00000000 0.1100 3.7500 - 1 6 0.000000 -1.400000 0.000000 0.00000000 0.1100 3.7500 - 1 6 -1.212436 -0.700000 0.000000 0.00000000 0.1100 3.7500 - 1 6 -1.212436 0.700000 0.000000 0.00000000 0.1100 3.7500 - 2 1 0.000000 2.488100 0.000000 0.00000000 0.0000 0.0000 - 2 1 2.154671 1.244000 0.000000 0.00000000 0.0000 0.0000 - 2 1 2.154671 -1.244000 0.000000 0.00000000 0.0000 0.0000 - 2 1 0.000000 -2.488100 0.000000 0.00000000 0.0000 0.0000 - 2 1 -2.154671 -1.244000 0.000000 0.00000000 0.0000 0.0000 - 2 1 -2.154671 1.244000 0.000000 0.00000000 0.0000 0.0000 + 1 6 1.407784 0.000000 0.000000 0.00000000 0.1100 3.7500 + 1 6 0.796966 1.274231 -0.338230 0.00000000 0.1100 3.7500 + 1 6 -0.703892 1.219173 -0.000000 0.00000000 0.1100 3.7500 + 1 6 -1.389932 -0.018988 0.227698 0.00000000 0.1100 3.7500 + 1 6 -0.703892 -1.219173 0.000000 0.00000000 0.1100 3.7500 + 1 6 0.703892 -1.219173 0.000000 0.00000000 0.1100 3.7500 + 2 1 2.501890 -0.000000 0.000000 0.00000000 0.0000 0.0000 + 2 1 1.415017 2.294961 -0.608843 0.00000000 0.0000 0.0000 + 2 1 -1.250943 2.166698 -0.000000 0.00000000 0.0000 0.0000 + 2 1 -2.501890 0.000000 0.000000 0.00000000 0.0000 0.0000 + 2 1 -0.519043 -2.235211 0.017991 0.00000000 0.0000 0.0000 + 2 1 1.250943 -2.166698 -0.000000 0.00000000 0.0000 0.0000 16 PLACEHOLDER 1 6 0.672026 -2.823446 0.002631 -0.11500000 0.0700 3.5500 1 6 2.072026 -2.823446 0.002631 -0.11500000 0.0700 3.5500