create_types
#
Create new tagged SMARTS parameter types for molecules of interest.
Functions:
-
add_types_to_forcefield–Add bespoke types to a force field based on multiple molecules and type generation settings.
-
add_library_charges_to_forcefield–Write per-atom
LibraryChargesfrom molecules' partial charges into a force field.
_add_parameter_with_overwrite
#
_add_parameter_with_overwrite(
handler: ParameterHandler,
parameter_dict: Mapping[str, str | Quantity],
) -> None
Add a parameter to a handler, overwriting any existing parameter with the same smirks.
Source code in presto/create_types.py
_create_smarts
#
Create a mapped SMARTS representation of a molecule.
Crucially, this uses MergeQueryHs to merge non-mapped hydrogens into their heavy atom. This dramatically increases the speed of SMARTS matching in RDKit for complex SMARTS patterns (thanks to Niels Maeder for suggesting this!).
Parameters:
-
mol(Molecule) –The molecule to create SMARTS for.
-
idxs(tuple[int, ...]) –Indices of the atoms to map (and from which to extend).
-
max_extend_distance(int, default:-1) –Maximum number of bonds to extend from the mapped atoms. If -1, include the entire molecule.
Returns:
str The SMARTS pattern with atom maps.
Source code in presto/create_types.py
_remove_redundant_smarts
#
_remove_redundant_smarts(
mols: Molecule | list[Molecule],
force_field: ForceField,
id_substring: str | None = None,
) -> ForceField
Remove redundant SMARTS parameters that are not used by any molecule.
This function labels all molecules with the force field and identifies which parameters are actually applied. Parameters that are not used by any molecule and have an ID containing the specified substring are removed. This works because the a given substructure should always be matched by the last equivalent mapped-SMARTS in the force field.
Parameters:
-
mols(Molecule | list[Molecule]) –Molecule or list of molecules to check parameter usage against
-
force_field(ForceField) –Force field to remove redundant parameters from
-
id_substring(str | None, default:None) –Only remove parameters whose ID contains this substring. If None, no parameters are removed.
Returns:
openff.toolkit.ForceField Force field with redundant parameters removed
Source code in presto/create_types.py
_remove_stereochemical_information
#
Return a copy of mol with atom and bond stereochemistry removed.
Source code in presto/create_types.py
add_types_to_forcefield
#
add_types_to_forcefield(
mols: Molecule | list[Molecule],
force_field: ForceField,
type_generation_settings: dict[
NonLinearValenceType, TypeGenerationSettings
],
) -> ForceField
Add bespoke types to a force field based on multiple molecules and type generation settings.
Parameters:
-
mols(Molecule | list[Molecule]) –Molecule or list of molecules to parameterize
-
force_field(ForceField) –The base force field to add bespoke parameters to
-
type_generation_settings(dict[NonLinearValenceType, TypeGenerationSettings]) –Settings for generating tagged SMARTS types for each valence type
Returns:
openff.toolkit.ForceField Force field with bespoke parameters added, deduplicated across all molecules
Source code in presto/create_types.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
add_library_charges_to_forcefield
#
add_library_charges_to_forcefield(
mols: Molecule | list[Molecule], force_field: ForceField
) -> ForceField
Write per-atom LibraryCharges from molecules' partial charges into a force field.
For each atom of each molecule a bespoke single-tagged-atom SMARTS spanning the
whole molecule is generated using the same machinery as the valence types (see
:func:add_types_to_forcefield). The charge assigned to each SMARTS is the mean
of the partial charges of all atoms that produce it (i.e. symmetry-equivalent
atoms), which both symmetrises equivalent atoms and preserves the total molecular
charge exactly.
Because the SMARTS spans the whole molecule, each one only matches its own
symmetry class, so every atom is covered by exactly one library charge and the net
charge of the molecule is reproduced. This is required because OpenFF interchange
does not renormalise charges: it only applies a LibraryCharges handler if it
covers every atom of the molecule, and otherwise raises if the assigned charges do
not sum to the formal charge. The non-tagged hydrogens are merged onto their heavy
atoms by MergeQueryHs for fast SMARTS matching.
Parameters:
-
mols(Molecule | list[Molecule]) –Molecule or molecules with
partial_chargesset. -
force_field(ForceField) –The base force field to add the library charges to.
Returns:
openff.toolkit.ForceField A copy of the force field with bespoke library charges added, deduplicated across all molecules.
Source code in presto/create_types.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |