Commit Graph

31 Commits

Author SHA1 Message Date
Kevin Boyd
232e4ffc84 Add Getter functions to MMFF property python interface (#9254) 2026-04-30 17:06:31 +02:00
Ricardo Rodriguez
a4b63d7df5 Minor refactor of the python wrappers (#8847)
* refactor python wrappers

* fix FilterHierarchyMatcher converted already registered warning
2025-10-05 09:42:31 +02:00
Ricardo Rodriguez
0164ac7fae Fix some more mem errors in 2024.09.1 (#7899)
* fixes

* do not leak MolCatalogParams

* do not leak points on align failures

* give python ownership of pointers returned in getFingerprintsHelper

* clean up ScaffoldNetwork ptr if createNetworkHelper fails

* manage FF ptrs during construction

* wire in ownsBondInvGenerator in getMorganGenerator

* manage weights in rdMolAlign CalcRMS

* fix ownership of matches list/tuple in generateRmsdTransMatchPyTuple

* manage stream in createForwardSupplier during construction

* drop redundant Point3D allocations in GetUSRDistributionsFromPoints

* fix signed comparison mismatch
2024-10-10 16:08:50 +02:00
Greg Landrum
3457c1eb60 a couple of additional cleanups (#7432) 2024-05-13 06:07:45 +02:00
Anna Brünisholz
d315e246e1 Cleanup: Force field (#7406)
* fix unsigned int to int comparison

* revert previous mistake

* declaration & init together, sinthetaSq in [0, 1]

* using std::swap

* use that sinThetaSq in [0,1]

* declare & init at same time

* use knowledge about target range

* use std::clamp

* use std::max

* numerically more stable trigonometrics

* numerically more stable trigonometrics

* numerically more stable trigonometrics

* range based for-loop

* actually do the assignement

* Update Code/ForceField/MMFF/Params.h

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>

* implemented suggested changes

* Revert "implemented suggested changes"

This reverts commit f56e8f0ab2.

* auto typing

* remove old comment

* revert to numerically more stable expression

* now correctly formatted

---------

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
2024-05-10 13:22:15 +02:00
Paolo Tosco
2b4202867e Add Python modules to generate stubs and automatically patch docstrings (#6919)
* - added gen_rdkit_stubs Python module to generate rdkit-stubs
- added patch_rdkit_docstrings Python module to patch existing C++ sources to fix docstrings missing self parameter and add named parameters taken from C++ signatures where possible
- added rdkit-stubs/CMakeLists.txt to build rdkit-stubs as part of the RDKit build
- added an option to CMakeLists.txt to enable building rdkit-stubs as part of the RDKit build (defaults to OFF)

* fixed CMakeLists.txt, rdkit-stubs/CMakeLists.txt and a doctest

* - added missing cmp_func parameter
- fixed case with overloads with optional parameters
- do not trim params if expected_param_count == -1
- add dummy parameter names if we could not find any
- keep into account member functions when making up parameter names
- address __init__ and make_constructor __init__ functions
- fix incorrectly assigned staticmethods

* patched sources

* address residual few remarks

---------

Co-authored-by: ptosco <paolo.tosco@novartis.com>
2023-11-30 04:54:18 +01:00
Greg Landrum
1f4584b2ca run clang_format (#5676) 2022-11-01 04:14:26 +01:00
Eisuke Kawashima
11532089de Run clang-format against cpp (#4358) 2021-10-20 04:25:27 +02:00
Greg Landrum
d41752d558 run clang-tidy with readability-braces-around-statements (#2899)
* run clang-tidy with readability-braces-around-statements
clang-format the results
clean up all the parts that clang-tidy-8 broke

* fix problem on windows
2020-01-25 14:19:32 +01:00
Paolo Tosco
995db8c18f Addresses GitHub #1688 (#1694)
* Addresses GitHub #1688

* - Addresses GitHub #1688 using a generic Python container rather than a Python list
2017-12-30 07:39:17 +00:00
Greg Landrum
915cf08faa run clang-format with c++-11 style over that 2017-04-22 17:19:10 +02:00
Greg Landrum
7c0bb0b743 clang-tidy output 2017-04-22 17:09:24 +02:00
Paolo Tosco
088256bfb1 - fixed a typo in the Python docs 2016-05-11 23:45:37 +01:00
Paolo Tosco
779ec747ac - put SnapshotVect in the RDKit namespace 2016-05-11 23:41:31 +01:00
Paolo Tosco
2b3a818f84 - removed the dependency on Trajectory from ROMol and ForceField 2016-05-11 19:37:09 +01:00
Paolo Tosco
d16b312ee6 - Completely revised coordinate ownership
- Implemented Python wrappers
- prepared relevant test cases
2016-04-24 23:30:25 +01:00
Greg Landrum
e08e0d16d8 first pass, using google style 2015-11-14 14:58:11 +01:00
Brian Kelley
403a3d6b7c Suppresses Boost warnings 2015-10-18 13:41:03 -04:00
Riccardo Vianello
7c346d7c2e Code/RDBoost/Exceptions.h moved to Code/RDGeneral 2015-03-16 22:31:48 +01:00
Greg Landrum
210a8635bf add units to force field docs 2015-01-29 14:05:16 +01:00
Greg Landrum
6c373ef11f - added C++ and Python helpers to retrieve force-field parameters
(i.e., equilibrium distances/angles and force constants) from
  UFF and MMFF in response to two requests recently appeared
  on the RDKit-discuss mailing list:
  http://sourceforge.net/p/rdkit/mailman/message/32953737/
  http://sourceforge.net/p/rdkit/mailman/message/32880156/
- did some clean up on the MMFF code
- NB there are two ABI changes:
  1) StretchBendContrib(ForceField *owner,
       const unsigned int idx1, const unsigned int idx2, const unsigned int idx3,
       const MMFFStbn *mmffStbnParams, const MMFFAngle *mmffAngleParams,
       const MMFFBond *mmffBondParams1, const MMFFBond *mmffBondParams2);
     previously was:
     StretchBendContrib(ForceField *owner,
       const unsigned int idx1, const unsigned int idx2, const unsigned int idx3,
       const std::pair<bool, const MMFFStbn *> mmffStbnParams,
       const MMFFAngle *mmffAngleParams, const MMFFBond *mmffBondParams1,
       const MMFFBond *mmffBondParams2);
  2) std::pair<double, double> calcStbnForceConstants(const MMFFStbn *mmffStbnParams);
     previously was:
     std::pair<double, double> calcStbnForceConstants
       (const std::pair<bool, const MMFFStbn *> mmffStbnParams);
  The two changes are NOT mandatory - however, both the StretchBendContrib constructor
  and calcStbnForceConstants(), though public, are basically "internal" method that
  most likely no-one has ever invoked. Given that the current API is MUCH better
  and cleaner, I would really advise for the new version.
2014-11-17 05:51:20 +01:00
ptosco
bc88b4393d - Fixed a bug in Code/GraphMol/MolAlign/testMolAlign.cpp which caused
data races in the multithreaded test
- Removed a spurious #include in Code/ForceField/Wrap/ForceField.cpp
- Restored caching in Code/GraphMol/Descriptors/Crippen.cpp
2014-01-24 14:20:34 +01:00
ptosco
5b70cdbdc1 - added relative DistanceConstraints (i.e., +/- with respect
to the current value) (C++/Python)
- added absolute/relative AngleConstraints (C++/Python)
- added absolute/relative TorsionConstraints (C++/Python)
- added PositionConstraints (C++/Python)
- exposed fixedPoints from Python
- added relevant C++/Python tests
- removed a number of redundant "this->" in member functions
- moved some getGrad() code into Utils::calcAngleBendGrad and
  Utils::calcTorsionGrad to avoid repeating the same code
  for constraints
2013-12-02 19:58:29 +01:00
ptosco
57147304bb - Replaced the setupMMFFForceField() function (which returned a pointer
to a newly allocated MMFFMolProperties object) with a simple
  constructor of the MMFFMolProperties object
- Replaced in a few MMFF-related functions the "ROMol *" argument
  with a "ROMol &" argument for consistency with similar RDKit
  functions
- Renamed the SetupMMFFForceField() function in Python into
  GetMMFFMolProperties() for consistency
- Updated the MMFF tests according to the aforementioned changes
  in the API
2013-09-28 18:45:51 +02:00
ptosco
b1acab59b0 - I have made MMFF atom typing more robust since I realized that
incorrect typing might arise when hydrogens were not added after
  generating 3D coordinates from SMILES strings; now all 761 test molecules
  are correctly typed no matter whether hydrogens are explicit or implicit

- MMFF test suite: I have cut down to the bare essential the
  MMFF94/MMFF94s reference log files, but their size could be reduced only
  by about 30%. It could have been reduced more converting multiple spaces
  into a tab, but the MMFF94 file (the larger one) would still be around
  11 MB, and human readability would be greatly impaired. Hence I decided
  to keep the spaces and gzip the reference logs, which reduces their
  combined size to ~ 3.5 MB, which I think is fine; the test program checks
  if the gunzipped files already exist, otherwise it gunzips them upfront.
  While cutting, I also sorted the molecules in the same order as in the
  SDF/SMILES files, so that it runs about 10 times faster than before.
  Now the test runs on MMFF94 only (MMFF94s only concerns different OOP
  parameters, there are no algorithmic differences, so as long as one does
  not alter the original parameters it can be safely skipped), computing
  every 4th molecule, and it runs in 12 seconds on my laptop. Running
  all molecules takes ~ 50 seconds, but I think it is rather overkill,
  and I would keep it as it is.

- I have added a test suite for MMFF ForceFieldHelpers (like the one
  already existing for UFF); I have also complemented the Python wrapper
  test suite for ForceFieldHelpers with a few tests for MMFF.

- I have written Python wrappers for the MMFF-related functionality;
  while doing that I realized that many of the wrapper code relocations
  that I made in my previous pull request were not necessary/appropriate,
  so I reverted them. The only difference from the UFF Python API is that,
  just like for the C++ API, in addition to the PyForceField object there
  is a PyMMFFMolProperties object which is created before constructing the
  force field itself; the PyMMFFMolProperties is necessary to set (e.g.,
  dielectric constant, dielectric model) or get (e.g., atom type, formal
  and partial charge) some MMFF properties which are not present in UFF,
  while preserving binary compatibility of the libraries. Probably you
  remember that we discussed about setting atom type and charge properties
  with SetProp besides populating the MMFFMolProperties object, in order
  to allow easy access to Python users. However, I think that the solution
  I adopted is preferrable since it is more consistent with the C++ API,
  it enables faster access to properties and it allows tailoring the MMFF
  environment (i.e., choosing MMFF94/MMFF94s, setting the verbosity level,
  including/excluding terms from the MMFF equation, setting dielectric
  constant/model) just as from C++.

  The MMFF-related Python functions I implemented are:

  * MMFFOptimizeMolecule(mol, mmffVariant = "MMFF94", maxIters = 200,
      nonBondedThresh = 100.0, confId = -1, ignoreInterfragInteractions
      = true)

    uses MMFF to optimize a molecule's structure (just like
    UFFOptimizeMolecule)

  * SanitizeMMFFMol(mol)

    sanitizes a molecule according to MMFF requirements

  * SetupMMFFForceField(mol, mmffVariant = "MMFF94", mmffVerbosity = 0)

    returns a PyMMFFMolProperties object for a molecule; the
    PyMMFFMolProperties object is required by MMFFGetMoleculeForceField()
    and can be used to get/set MMFF properties

  * MMFFGetMoleculeForceField(mol, pyMMFFMolProperties,
      nonBondedThresh = 100.0, confId = -1, ignoreInterfragInteractions
      = true)

    returns a MMFF force field for a molecule (just like
    UFFGetMoleculeForceField)

  * MMFFHasAllMoleculeParams(mol)

    checks if MMFF parameters are available for all of a molecule's atoms
    (just like UFFHasAllMoleculeParams)

  There are also a few methods connected to the PyMMFFMolProperties class
  which mirror those available from C++ for the MMFFMolProperties class:

  * GetMMFFAtomType(idx)

    Retrieves MMFF atom type for atom with index idx

  * GetMMFFFormalCharge(idx)

    Retrieves MMFF formal charge for atom with index idx

  * GetMMFFPartialCharge(idx)

    Retrieves MMFF partial charge for atom with index idx

  * SetMMFFDielectricModel(dielModel = 1)

    sets the DielModel MMFF property (1: constant; 2: distance-dependent;
    defaults to constant)

  * SetMMFFDielectricConstant(dielConst = 1.0)

    Sets the DielConst MMFF property (defaults to 1.0)

  * SetMMFFBondTerm(state = True)

    Sets the bond term to be included in the MMFF equation (defaults
    to True)

  * SetMMFFAngleTerm(state = True)

    Sets the angle term to be included in the MMFF equation (defaults
    to True)

  * SetMMFFStretchBendTerm(state = True)

    Sets the stretch-bend term to be included in the MMFF equation (defaults
    to True)

  * SetMMFFOopTerm(state = True)

    Sets the out-of-plane bend term to be included in the MMFF equation
    (defaults to True)

  * SetMMFFTorsionTerm(state = True)

    Sets the torsional term to be included in the MMFF equation (defaults
    to True)

  * SetMMFFVdWTerm(state = True)

    Sets the Van der Waals term to be included in the MMFF equation
    (defaults to True)

  * SetMMFFEleTerm(state = True)

    Sets the electrostatic term to be included in the MMFF equation
    (defaults to True)

  * SetMMFFVariant(mmffVariant = "MMFF94")

    Sets the MMFF variant to be used ("MMFF94" or "MMFF94s"; defaults to
    "MMFF94")

  * SetMMFFVerbosity(verbosity = 0)

    Sets the MMFF verbosity (0: none; 1: low; 2: high; defaults to 0)

  Hence, most users will do something like this to optimize a molecule
  structure obtained from a SMILES string:

  from rdkit import Chem
  from rdkit.Chem import AllChem

  m = Chem.MolFromSmiles("O=C(C)c1cccnc1", False)
  AllChem.SanitizeMMFFMol(m)
  m2 = Chem.AddHs(m)
  AllChem.EmbedMolecule(m2)
  # Opt
  AllChem.MMFFOptimizeMolecule(m2)
  print >>file('structure_min.sdf','w'), Chem.MolToMolBlock(m2)

  Those willing to play a bit more with MMFF properties may do the
  following:

  from rdkit import Chem
  from rdkit.Chem import AllChem

  m = Chem.MolFromSmiles("O=C(C)c1cccnc1", False)
  AllChem.SanitizeMMFFMol(m)
  m2 = Chem.AddHs(m)
  AllChem.EmbedMolecule(m2)
  pyMP = AllChem.SetupMMFFForceField(m2)
  pyMP.SetMMFFVariant("MMFF94s")
  pyMP.SetMMFFDielectricModel(2)
  pyFF = AllChem.MMFFGetMoleculeForceField(m2, pyMP)
  pyFF.Minimize()
  print >>file('structure_min.sdf','w'), Chem.MolToMolBlock(m2)
  print 'Energy = {0:12.4f}'.format(pyFF.CalcEnergy())
  i = 0
  for i in range(0, m2.GetNumAtoms()):
    print '{0:4d} {1:4d} {2:8.4f} {3:8.4f}'.format(i + 1,
      int(pyMP.GetMMFFAtomType(i)),
      float(pyMP.GetMMFFFormalCharge(i)),
      float(pyMP.GetMMFFPartialCharge(i)))

- OOP backport to UFF. I added the inversion term to the UFF
  implementation following the original UFF paper by Rappe'. I have already
  modified the figures in a couple of test files to reflect the new energy
  values.

- 2-bit neighbor matrix and graph-based angle enumeration now reflect
  the MMFF implementation.
2013-09-16 12:08:02 +02:00
ptosco
3f4297fa44 Created a new MMFF branch. I moved some files/folders from
Code/ForceField and Code/GraphMol/ForceFieldHelpers to the
respective UFF subfolders since from now on UFF will not be
the only available force field anymore. I updated the
relevant CMakeLists.txt files accordingly.

Paolo
2013-08-18 09:11:29 +02:00
Greg Landrum
c9161554b9 clean up some compiler warnings from clang 2011-05-26 02:36:23 +00:00
Greg Landrum
f3fbef45c5 update copyright statements 2010-09-26 17:04:37 +00:00
Greg Landrum
a3e6cb057e this is a mass of cleanup stuff; mostly line endings 2008-07-07 13:21:24 +00:00
Greg Landrum
5d03333c22 setup svn keywords (should have done this before import... grn) 2006-05-06 22:54:39 +00:00
Greg Landrum
75a79b6327 initial import 2006-05-06 22:20:08 +00:00