Skip to content

Commit

Permalink
some fixes w.r.t. part execution
Browse files Browse the repository at this point in the history
  • Loading branch information
lmseidler committed Oct 28, 2024
1 parent 518219b commit 10305b8
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/censo/ensembledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def __setup_conformers(self, input_path: str, maxconf: int = None) -> None:
self.__conformers.append(
MoleculeData(
confname,
lines[conf_index:conf_end_index],
lines[conf_index + 2 : conf_end_index],
)
)

Expand Down
11 changes: 5 additions & 6 deletions src/censo/ensembleopt/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def _optimize(self, cut: bool = True) -> None:
self.ensemble.remove_conformers(failed)

# update results for each conformer
self.results.update(results_opt)
for conf in self.ensemble.conformers:
self.results[conf.name].update(results_opt[conf.name])
# update geometry of the conformer
conf.geom.xyz = results_opt[conf.name][jobtype[0]]["geom"]

Expand Down Expand Up @@ -193,19 +193,18 @@ def _optimize(self, cut: bool = True) -> None:
# Remove failed conformers
self.ensemble.remove_conformers(failed)

# Update results
self.results.update(results)

# TODO - Add the possibility to explicitely calculate solvation contributions

# Update results
for conf in self.ensemble.conformers:
self.results[conf.name].update(results[conf.name])
self.results[conf.name]["gtot"] = self._grrho(conf)

# sort conformers list with optimization key (gtot)
self.ensemble.conformers.sort(key=lambda conf: self.results[conf.name]["gtot"])

# calculate boltzmann weights from gtot values calculated here
self.results.update(self._calc_boltzmannweights())
self._calc_boltzmannweights()

# write final results
self._write_results()
Expand Down Expand Up @@ -337,10 +336,10 @@ def __macrocycle_opt(self, cut: bool):
self.set_general_setting("bhess", tmp)

# Update results
self.results.update(results)
for conf in filter(
lambda x: x.name in self.confs_nc, self.ensemble.conformers
):
self.results[conf.name].update(results[conf.name])
self.results[conf.name]["gtot"] = self._grrho(conf)

# flag to make sure that rrho is only calculated once
Expand Down
2 changes: 1 addition & 1 deletion src/censo/ensembleopt/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _validate(cls, tovalidate: dict[str, any]) -> None:

@timeit
@CensoPart._create_dir
def __call__(self, ensemble: EnsembleData, cut: bool = True) -> None:
def __call__(self, cut: bool = True) -> None:
"""
Boilerplate run logic for any ensemble optimization step. The 'optimize' method should be implemented for every
class respectively.
Expand Down
12 changes: 6 additions & 6 deletions src/censo/ensembleopt/prescreening.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def _optimize(self, cut: bool = True) -> None:
self.ensemble.remove_conformers(failed)

# Update results
self.results.update(results)
for conf in self.ensemble.conformers:
self.results[conf.name].update(results[conf.name])

jobtype = ["sp"]
else:
Expand All @@ -108,10 +109,9 @@ def _optimize(self, cut: bool = True) -> None:
self.ensemble.remove_conformers(failed)

# Update results
self.results.update(results)

# update results for each conformer
for conf in self.ensemble.conformers:
self.results[conf.name].update(results[conf.name])

# calculate free enthalpy
self.results[conf.name]["gtot"] = self._gsolv(conf)

Expand All @@ -121,14 +121,14 @@ def _optimize(self, cut: bool = True) -> None:
)

# calculate boltzmann weights from gtot values calculated here
self.results.update(self._calc_boltzmannweights())
self._calc_boltzmannweights()

self._write_results()

if cut:
print("\n")
# update conformers with threshold
threshold = self.get_settings()["threshold"] / Params.Params.AU2KCAL
threshold = self.get_settings()["threshold"] / Params.AU2KCAL
limit = min(
self.results[conf.name]["gtot"] for conf in self.ensemble.conformers
)
Expand Down
9 changes: 4 additions & 5 deletions src/censo/ensembleopt/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def _optimize(self, cut: bool = True) -> None:
self.ensemble.remove_conformers(failed)

# Update results
self.results.update(results)

for conf in self.ensemble.conformers:
self.results[conf.name].update(results[conf.name])

# calculate new gtot including RRHO contribution
self.results[conf.name]["gtot"] = self._grrho(conf)
else:
Expand All @@ -88,8 +88,7 @@ def _optimize(self, cut: bool = True) -> None:
self.ensemble.conformers.sort(key=lambda conf: self.results[conf.name]["gtot"])

# calculate boltzmann weights from gtot values calculated here
# trying to get temperature from instructions, set it to room temperature if that fails for some reason
self.results.update(self._calc_boltzmannweights())
self._calc_boltzmannweights()

if cut:
# Get Boltzmann population threshold from settings
Expand All @@ -111,7 +110,7 @@ def _optimize(self, cut: bool = True) -> None:
print(f"No longer considering {confname}.")

# Recalculate boltzmann weights after cutting down the ensemble
self.results.update(self._calc_boltzmannweights())
self._calc_boltzmannweights()

# second 'write_results' for the updated sorting with RRHO contributions
self._write_results2()
Expand Down
6 changes: 2 additions & 4 deletions src/censo/ensembleopt/screening.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ def _optimize(self, cut: bool = True) -> None:
self.ensemble.remove_conformers(failed)

# Update results
self.results.update(results)

for conf in self.ensemble.conformers:
self.results[conf.name].update(results[conf.name])
# calculate new gtot including RRHO contribution
self.results[conf.name]["gtot"] = self._grrho(conf)

Expand Down Expand Up @@ -125,8 +124,7 @@ def _optimize(self, cut: bool = True) -> None:
print(f"No longer considering {confname}.")

# calculate boltzmann weights from gtot values calculated here
# trying to get temperature from instructions, set it to room temperature if that fails for some reason
self.results.update(self._calc_boltzmannweights())
self._calc_boltzmannweights()

# if no conformers are filtered basically nothing happens

Expand Down
2 changes: 1 addition & 1 deletion src/censo/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def dqp(jobs: list[ParallelJob], processor: QmProc) -> list[ParallelJob]:

try:
# submit the job
tasks.append(executor.submit(processor.run, jobs[i]))
tasks.append(executor.submit(processor, jobs[i]))
# NOTE: explanation of the lambda: the first argument passed to the done_callback is always the future
# itself, it is not assigned (_), the second parameter is the number of openmp threads of the job (i.e.
# job.omp) if this is not specified like this (omp=jobs[i].omp) the done_callback will instead use the
Expand Down
13 changes: 7 additions & 6 deletions src/censo/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,14 @@ def wrapper(self, *args, **kwargs):

return wrapper

def __init__(self, ensemble: EnsembleData):
def __init__(self, ensemble: EnsembleData, dry: bool = False):
"""
Initializes a part instance. Also calls the new instance in a single step.
Yields the instance after execution of itself.
Args:
ensemble: The ensemble instance that manages the conformers.
dry: If True, the part will not be executed.
Returns:
None
Expand Down Expand Up @@ -326,7 +327,8 @@ def __init__(self, ensemble: EnsembleData):
# to get the single-point energy: self.results["CONF3"]["sp"]["energy"]
# (refer to the results for each jobtype)

self.runtime = self()
if not dry:
self.runtime = self()

# Attach a reference to this part to the ensemble
self.ensemble.results.append(self)
Expand All @@ -338,7 +340,7 @@ def __call__(self) -> None:
"""
pass

def _calc_boltzmannweights(self) -> dict:
def _calc_boltzmannweights(self) -> None:
"""
Calculate populations for boltzmann distribution of ensemble at given
temperature given values for free enthalpy.
Expand Down Expand Up @@ -402,9 +404,8 @@ def _calc_boltzmannweights(self) -> dict:
bsum: float = sum(bmfactors.values())

# Return Boltzmann populations
return {
conf.name: bmfactors[conf.name] / bsum for conf in self.ensemble.conformers
}
for conf in self.ensemble.conformers:
self.results[conf.name]["bmw"] = bmfactors[conf.name] / bsum

def _print_info(self) -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion src/censo/properties/nmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def _property(self) -> None:
self.ensemble.remove_conformers(failed)

# Update results
self.results.update(results)
for conf in self.ensemble.conformers:
self.results[conf.name].update(results[conf.name])

# Generate files for ANMR
self.__generate_anmr()
Expand Down
2 changes: 1 addition & 1 deletion src/censo/properties/property_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class respectively.
self.results[conf.name]["gtot"] = self._gtot(conf)

# Calculate Boltzmann populations
self.results.update(self._calc_boltzmannweights())
self._calc_boltzmannweights()

# Perform the property calculations
self._property()
Expand Down
3 changes: 2 additions & 1 deletion src/censo/properties/uvvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def _property(self) -> None:
self.ensemble.remove_conformers(failed)

# Update results
self.results.update(results)
for conf in self.ensemble.conformers:
self.results[conf.name].update(results[conf.name])

# Ensemble averaging of excitations
self.__excitation_averaging()
Expand Down
2 changes: 1 addition & 1 deletion src/censo/qm_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(self, workdir: str):

self.workdir = workdir

def run(self, job: ParallelJob) -> ParallelJob:
def __call__(self, job: ParallelJob) -> ParallelJob:
"""
Run methods depending on jobtype.
DO NOT OVERRIDE OR OVERLOAD! this will break e.g. censo.parallel.execute
Expand Down

0 comments on commit 10305b8

Please sign in to comment.