Skip to content

Commit 3cd12ce

Browse files
committed
Generalise CT
1 parent 6e93c57 commit 3cd12ce

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

src/fes_ml/alchemical/modifications/charge_transfer.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def apply(
9090
system: _mm.System,
9191
alchemical_atoms: List[int],
9292
original_offxml: List[str],
93+
ct_offxml: str,
9394
topology_off: _Topology,
9495
lambda_value: Optional[Union[float, int]] = 1.0,
9596
*args,
@@ -104,6 +105,8 @@ def apply(
104105
The system to be modified.
105106
alchemical_atoms : list of int
106107
The indices of the alchemical atoms in the system.
108+
ct_offxml: str
109+
Path to the offxml file containing the charge transfer parameters.
107110
original_offxml : List[str]
108111
List of paths to the original offxml files.
109112
topology_off : openff.toolkit.topology.Topology
@@ -120,34 +123,12 @@ def apply(
120123
openmm.System
121124
The modified system.
122125
"""
123-
ct_paraams = {
124-
"n21": {"sigma": 3.1739, "eps": 169.0640},
125-
"n16": {"sigma": 4.3983, "eps": 42.4290},
126-
"n3": {"sigma": 5.9554, "eps": 0.1890},
127-
"n-tip3p-O": {"sigma": 5.5019, "eps": 119.9913},
128-
"n-tip3p-H": {"sigma": 5.6480, "eps": 3.4209},
129-
"n20": {"sigma": 4.1808, "eps": 71.9843},
130-
"n2": {"sigma": 7.6786, "eps": 0.1502},
131-
"n18": {"sigma": 4.7983, "eps": 78.6935},
132-
"n14": {"sigma": 3.9557, "eps": 50.0886},
133-
"n17": {"sigma": 4.6716, "eps": 61.3267},
134-
"n9": {"sigma": 5.2866, "eps": 0.8104},
135-
"n4": {"sigma": 5.8806, "eps": 0.4651},
136-
"n13": {"sigma": 5.3179, "eps": 1.1033},
137-
"n11": {"sigma": 5.2541, "eps": 0.7611},
138-
"n19": {"sigma": 4.9034, "eps": 75.1253},
139-
"n12": {"sigma": 4.6507, "eps": 1.0854},
140-
"n7": {"sigma": 6.8461, "eps": 0.5855},
141-
"n15": {"sigma": 4.3835, "eps": 59.0651},
142-
"n10": {"sigma": 5.3841, "eps": 0.4192},
143-
"n8": {"sigma": 6.7245, "eps": 0.7046},
144-
}
145-
146-
energy_function = f"-{lambda_value}*donor_acceptor*epsilon*exp(-sigma*r);"
147-
energy_function += "sigma = 0.5*(sigma1+sigma2);"
148-
energy_function += "epsilon = sqrt(epsilon1*epsilon2);"
126+
# Convert units
127+
energy_function = f"-{lambda_value}*donor_acceptor*epsilon*exp(-r/sigma);"
128+
energy_function += "sigma = sqrt(sigma1*sigma2);"
129+
energy_function += "epsilon = (epsilon1*epsilon2);"
149130
energy_function += (
150-
"donor_acceptor = isDonor1*isAcceptor2 + isDonor2*isAcceptor1;"
131+
"donor_acceptor = 1;"#isDonor1*isAcceptor2 + isDonor2*isAcceptor1;"
151132
)
152133

153134
logger.debug(f"Charge transfer function: {energy_function}")
@@ -163,28 +144,43 @@ def apply(
163144
# Add per-particle parameters to the CustomNonbondedForce
164145
charge_transfer_force.addPerParticleParameter("sigma")
165146
charge_transfer_force.addPerParticleParameter("epsilon")
166-
charge_transfer_force.addPerParticleParameter("isDonor")
167-
charge_transfer_force.addPerParticleParameter("isAcceptor")
147+
#charge_transfer_force.addPerParticleParameter("isDonor")
148+
#charge_transfer_force.addPerParticleParameter("isAcceptor")
168149

169150
# Update the Lennard-Jones parameters in the CustomNonbondedForce
170-
force_field = _ForceField(*original_offxml)
171-
labels = force_field.label_molecules(topology_off)
151+
#force_field = _ForceField(*original_offxml)
152+
#labels = force_field.label_molecules(topology_off)
172153

173154
# Get atom types
174-
atom_types = [val.id for mol in labels for _, val in mol["vdW"].items()]
155+
#atom_types = [val.id for mol in labels for _, val in mol["vdW"].items()]
175156

176157
# Get donor/acceptor flags
177158
is_donor, is_acceptor = ChargeTransferModification.get_is_donor_acceptor(
178159
topology_off, alchemical_atoms
179160
)
180161

162+
# CT force field
163+
ct_force_field = _ForceField(ct_offxml)
164+
labels = ct_force_field.label_molecules(topology_off)
165+
ct_params = {
166+
p.id: {
167+
"epsilon": p.epsilon.to_openmm().value_in_unit(
168+
_unit.kilojoules_per_mole
169+
),
170+
"sigma": p.sigma.to_openmm().value_in_unit(_unit.nanometer),
171+
}
172+
for p in ct_force_field.get_parameter_handler("vdW")
173+
}
174+
atom_types = [val.id for mol in labels for _, val in mol["vdW"].items()]
175+
181176
for index in range(system.getNumParticles()):
177+
at_type = atom_types[index]
182178
charge_transfer_force.addParticle(
183179
[
184-
ct_paraams.get(atom_types[index], {}).get("sigma", 0) * 10,
185-
ct_paraams.get(atom_types[index], {}).get("eps", 0) * 1e3,
186-
is_donor[index],
187-
is_acceptor[index],
180+
ct_params[at_type]["sigma"],
181+
ct_params[at_type]["epsilon"],# * 10.0,
182+
#is_donor[index],
183+
#is_acceptor[index],
188184
]
189185
)
190186

0 commit comments

Comments
 (0)