1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// $Id$
//
// Copyright (C) 2005-2008 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#define PY_ARRAY_UNIQUE_SYMBOL rdmoltransforms_array_API
#include <RDBoost/python.h>
#include <RDBoost/import_array.h>
#include "numpy/arrayobject.h"
#include <GraphMol/ROMol.h>
#include <RDBoost/Wrap.h>
#include <GraphMol/Conformer.h>
#include <GraphMol/MolTransforms/MolTransforms.h>
#include <Geometry/Transform3D.h>
#include <Geometry/point.h>
namespace python = boost::python;
namespace RDKit {
PyObject *computeCanonTrans(const Conformer &conf,
const RDGeom::Point3D *center = 0,
bool normalizeCovar = false, bool ignoreHs = true) {
RDGeom::Transform3D *trans;
trans = MolTransforms::computeCanonicalTransform(conf, center, normalizeCovar,
ignoreHs);
npy_intp dims[2];
dims[0] = 4;
dims[1] = 4;
PyArrayObject *res = (PyArrayObject *)PyArray_SimpleNew(2, dims, NPY_DOUBLE);
double *resData = reinterpret_cast<double *>(PyArray_DATA(res));
const double *tdata = trans->getData();
memcpy(static_cast<void *>(resData), static_cast<const void *>(tdata),
4 * 4 * sizeof(double));
delete trans;
return PyArray_Return(res);
}
void transConformer(Conformer &conf, python::object trans) {
PyObject *transObj = trans.ptr();
if (!PyArray_Check(transObj)) {
throw_value_error("Expecting a numeric array for transformation");
}
PyArrayObject *transMat = reinterpret_cast<PyArrayObject *>(transObj);
unsigned int nrows = PyArray_DIM(transMat, 0);
unsigned int dSize = nrows * nrows;
double *inData = reinterpret_cast<double *>(PyArray_DATA(transMat));
RDGeom::Transform3D transform;
double *tData = transform.getData();
memcpy(static_cast<void *>(tData), static_cast<void *>(inData),
dSize * sizeof(double));
MolTransforms::transformConformer(conf, transform);
}
}
BOOST_PYTHON_MODULE(rdMolTransforms) {
python::scope().attr("__doc__") =
"Module containing functions to perform 3D operations like rotate and "
"translate conformations";
rdkit_import_array();
std::string docString =
"Compute the centroid of the conformation - hydrogens are ignored and no attention\n\
if paid to the difference in sizes of the heavy atoms\n";
python::def("ComputeCentroid", MolTransforms::computeCentroid,
(python::arg("conf"), python::arg("ignoreHs") = true),
docString.c_str());
docString =
"Compute the transformation required aligna conformer so that\n\
the the principal axes align up with the x,y, z axes\n\
The conformer itself is left unchanged\n\
ARGUMENTS:\n\
- conf : the conformer of interest\n\
- center : optional center point to compute the principal axes around (defaults to the centroid)\n\
- normalizeCovar : optionally normalize the covariance matrix by the number of atoms\n";
python::def(
"ComputeCanonicalTransform", RDKit::computeCanonTrans,
(python::arg("conf"), python::arg("center") = (RDGeom::Point3D *)(0),
python::arg("normalizeCovar") = false, python::arg("ignoreHs") = true),
docString.c_str());
python::def("TransformConformer", RDKit::transConformer,
"Transform the coordinates of a conformer");
docString =
"Canonicalize the orientation of a conformer so that its principal axes\n\
around the specified center point coincide with the x, y, z axes\n\
\n\
ARGUMENTS:\n\
- conf : conformer of interest \n\
- center : optionally center point about which the principal axes are computed \n\
if not specified the centroid of the conformer will be used\n\
- normalizeCovar : Optionally normalize the covariance matrix by the number of atoms\n";
python::def(
"CanonicalizeConformer", MolTransforms::canonicalizeConformer,
(python::arg("conf"), python::arg("center") = (RDGeom::Point3D *)(0),
python::arg("normalizeCovar") = false, python::arg("ignoreHs") = true),
docString.c_str());
python::def("CanonicalizeMol", MolTransforms::canonicalizeMol,
(python::arg("mol"), python::arg("normalizeCovar") = false,
python::arg("ignoreHs") = true),
"Loop over the conformers in a molecule and canonicalize their "
"orientation");
python::def(
"GetBondLength", &MolTransforms::getBondLength,
(python::arg("conf"), python::arg("iAtomId"), python::arg("jAtomId")),
"Returns the bond length in angstrom between atoms i, j\n");
python::def("SetBondLength", &MolTransforms::setBondLength,
(python::arg("conf"), python::arg("iAtomId"),
python::arg("jAtomId"), python::arg("value")),
"Sets the bond length in angstrom between atoms i, j; "
"all atoms bonded to atom j are moved\n");
python::def("GetAngleRad", &MolTransforms::getAngleRad,
(python::arg("conf"), python::arg("iAtomId"),
python::arg("jAtomId"), python::arg("kAtomId")),
"Returns the angle in radians between atoms i, j, k\n");
python::def("GetAngleDeg", &MolTransforms::getAngleDeg,
(python::arg("conf"), python::arg("iAtomId"),
python::arg("jAtomId"), python::arg("kAtomId")),
"Returns the angle in degrees between atoms i, j, k\n");
python::def(
"SetAngleRad", &MolTransforms::setAngleRad,
(python::arg("conf"), python::arg("iAtomId"), python::arg("jAtomId"),
python::arg("kAtomId"), python::arg("value")),
"Sets the angle in radians between atoms i, j, k; "
"all atoms bonded to atom k are moved\n");
python::def(
"SetAngleDeg", &MolTransforms::setAngleDeg,
(python::arg("conf"), python::arg("iAtomId"), python::arg("jAtomId"),
python::arg("kAtomId"), python::arg("value")),
"Sets the angle in degrees between atoms i, j, k; "
"all atoms bonded to atom k are moved\n");
python::def(
"GetDihedralRad", &MolTransforms::getDihedralRad,
(python::arg("conf"), python::arg("iAtomId"), python::arg("jAtomId"),
python::arg("kAtomId"), python::arg("lAtomId")),
"Returns the dihedral angle in radians between atoms i, j, k, l\n");
python::def(
"GetDihedralDeg", &MolTransforms::getDihedralDeg,
(python::arg("conf"), python::arg("iAtomId"), python::arg("jAtomId"),
python::arg("kAtomId"), python::arg("lAtomId")),
"Returns the dihedral angle in degrees between atoms i, j, k, l\n");
python::def(
"SetDihedralRad", &MolTransforms::setDihedralRad,
(python::arg("conf"), python::arg("iAtomId"), python::arg("jAtomId"),
python::arg("kAtomId"), python::arg("lAtomId"), python::arg("value")),
"Sets the dihedral angle in radians between atoms i, j, k, l; "
"all atoms bonded to atom l are moved\n");
python::def("SetDihedralDeg", &MolTransforms::setDihedralDeg,
"Sets the dihedral angle in degrees between atoms i, j, k, l; "
"all atoms bonded to atom l are moved\n");
}
|