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_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:
-
ForceField–Force field with redundant parameters removed
Source code in presto/create_types.py
_add_types_to_parameter_handler
#
_add_types_to_parameter_handler(
mol: Molecule,
parameter_handler: _T,
handler_name: str,
max_extend_distance: int = -1,
excluded_smirks: list[str] | None = None,
included_smirks: list[str] | None = None,
) -> _T
Add bespoke parameters to the parameter handler based on the molecule.
This:
a) Labels the molecule with the original parameter types from the
parameter handler (using find_matches).
b) For each set of atoms labelled using the original parameters:
i) Check that it is not excluded (if excluded_smirks is
provided) or is included (if included_smirks is provided).
ii) Create a SMARTS pattern that extends from the labelled atoms up
to max_extend_distance bonds.
iii) Add a new parameter to the parameter handler with the created
SMARTS pattern. If a parameter with the same SMARTS pattern
already exists, log a warning and skip adding the new parameter.
Parameters:
-
mol(Molecule) –The molecule to parameterise.
-
parameter_handler(_T) –openff.toolkit.typing.engines.smirnoff.parameters.ParameterHandler
-
handler_name(str) –The name of the parameter handler.
-
max_extend_distance(int, default:-1) –The maximum distance (in bonds) to extend the SMARTS patterns from the atoms which determine the energy for the parameter. If -1, the SMARTS patterns will include the entire molecule.
-
excluded_smirks(list[str] | None, default:None) –A list of SMIRKS patterns to exclude from bespoke type generation. This is mutually exclusive with
included_smirks. -
included_smirks(list[str] | None, default:None) –A list of SMIRKS patterns to include in bespoke type generation. This is mutually exclusive with
excluded_smirks.
Returns:
-
ParameterHandler–The parameter handler with bespoke parameters added.
Source code in presto/create_types.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 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 | |
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:
-
ForceField–Force field with bespoke parameters added, deduplicated across all molecules
Source code in presto/create_types.py
327 328 329 330 331 332 333 334 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 | |