Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camilos fixes #457

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 3 additions & 1 deletion src/kimmdy/kmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ def rf_kmc(
reaction_probability = []

# 1. Calculate the probability for each reaction

for recipe in recipe_collection.recipes:
dt = [x[1] - x[0] for x in recipe.timespans]
reaction_probability.append(sum(np.multiply(dt, recipe.rates)))
t_interval = recipe.timespans[-1][-1] - recipe.timespans[0][0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calculates the time between the first time this recipe becomes valid, and the last time it is valid. However, in between it might be invalid.
If the reaction probability should be scaled down by the time it should be ?

sum(dt)

reaction_probability.append(sum(np.multiply(dt, recipe.rates)) / t_interval)

# 2. Set the total rate to the sum of individual rates
probability_cumulative = np.cumsum(reaction_probability)
Expand Down
43 changes: 35 additions & 8 deletions src/kimmdy/topology/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ def update_partial_charges(self, recipe_steps: list[RecipeStep]) -> None:
# not need to be repeated
# Warning: resnr not unique for each residue, 'residues' can map to
# more than one real residue

residues = {}
for atom in self.atoms.values():
if residues.get(atom.resnr) is None:
Expand Down Expand Up @@ -1025,6 +1026,14 @@ def update_partial_charges(self, recipe_steps: list[RecipeStep]) -> None:
atom2 = self.atoms[step.atom_id_2]
# check whether bond exists in topology
residue = atom1.residue

# only attempt update if residuetype exists
if self.ff.residuetypes.get(residue) is None:
logger.warning(
f"Residue `{residue}` not in list of residuetypes. Not changing partial charges for Bind recipe step {step}!"
)
continue

bondtype = (atom1.atom, atom2.atom)
residue_bond_spec = self.ff.residuetypes[residue].bonds.get(
bondtype,
Expand Down Expand Up @@ -1385,8 +1394,7 @@ def bind_bond(
if reactive_moleculetype.angles.get(key) is None:
reactive_moleculetype.angles[key] = Angle(key[0], key[1], key[2], "1")

# add proper and improper dihedrals
# add proper dihedrals and pairs
# add proper dihedrals
# TODO; for now this assumes function type 9 for all dihedrals
# and adds all possible dihedrals (and pairs)
# later we should check the ff if there are multiple
Expand All @@ -1396,12 +1404,11 @@ def bind_bond(
) + reactive_moleculetype._get_atom_proper_dihedrals(atompair_nrs[1])
for key in dihedral_keys:
if reactive_moleculetype.proper_dihedrals.get(key) is None:
reactive_moleculetype.proper_dihedrals[key] = MultipleDihedrals(
*key, "9", dihedrals={"": Dihedral(*key, "9")}
)
pairkey: tuple[str, str] = tuple(str(x) for x in sorted([key[0], key[3]], key=int)) # type: ignore
if reactive_moleculetype.pairs.get(pairkey) is None:
reactive_moleculetype.pairs[pairkey] = Pair(pairkey[0], pairkey[1], "1")
# check for three membered ring
if not key[0] == key[-1]:
reactive_moleculetype.proper_dihedrals[key] = MultipleDihedrals(
*key, "9", dihedrals={"": Dihedral(*key, "9")}
)

# improper dihedral
dihedral_k_v = reactive_moleculetype._get_atom_improper_dihedrals(
Expand All @@ -1417,3 +1424,23 @@ def bind_bond(
reactive_moleculetype.improper_dihedrals[key].dihedrals[value.c2] = (
Dihedral(*key, "4", c0=value.c0, c1=value.c1, periodicity=value.c2)
)

# add pairs for the most distant excluded bonded interaction
scaled_interaction_keys = {
"1": [atompair_nrs],
"2": angle_keys,
"3": dihedral_keys,
}
try:
for key in scaled_interaction_keys[reactive_moleculetype.nrexcl]:
# check for three membered ring in propers, not harmful for bonds, angles
if not key[0] == key[-1]:
pairkey: tuple[str, str] = tuple(str(x) for x in sorted([key[0], key[-1]], key=int)) # type: ignore
if reactive_moleculetype.pairs.get(pairkey) is None:
reactive_moleculetype.pairs[pairkey] = Pair(
pairkey[0], pairkey[1], "1"
)
except KeyError:
logger.exception(
f"Unexpected nrexcl: {reactive_moleculetype.nrexcl}, should be in [1,2,3]! Skipping pairs generation."
)
2 changes: 1 addition & 1 deletion src/kimmdy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def truncate_sim_files(files: TaskFiles, time: Optional[float], keep_tail: bool
paths["gro"].with_name("tmp_backup_" + paths["gro"].name)
)
sp.run(
f"gmx trjconv -f {trjs[0]} -s {bck_gro} -dump -1 -o {paths['gro']}",
f"gmx trjconv -f {trjs[0]} -s {bck_gro} -dump {time} -o {paths['gro']}",
text=True,
input="0",
shell=True,
Expand Down
Loading