mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
* Add RealValueVect.
* Add UniformRealValueGrid3D
* Add Molecular Interaction Fields (MIFs)
* line endings
* cherry-pick f1bc94a4c8
* format
* Adapt tests for python3.
* Adapt RealValueVector pickling for python3.
* Speed-up of MIF calculations.
* Bugfix in MIFDescriptors.cpp.
* all tests pass
* clean up some memory leaks
* update copyrights
* rename
* rename the library
* complete the rename
* lost file
* another forgotten file
* cleanup
* clang-tidy
* clang-tidy
* windows DLL builds work
* python wrapper and tests cleanup
* convert to catch2 testing
* switch RealValueVect to use std::vector
* remove obsolete friend
* - Replace explicit loops with stdlib implicit equivalents
- Replace explicit types with auto where possible
- Avoid unnecessary copy operations where possible
- Replace raw pointers with exception-safe unique_ptr
- Replace C-style #define with constexpr
- Replace C-style casts with C++ casts
- Replace C-style arrays with std::vector
- Avoid code duplication with templated operators
- Replace VdWaals class taking multiple atom type definitions and force-field name as string parameter with force-field-specific classes deriving from an abstract VdWaals class
- Replace x,y,z doubles with Point3D class where possible
- Removed unused (and untested) DistanceToClosestAtom class
- Renamed some variables and functions for better clarity
- Converted tabs to spaces
- Made the mol parameter in cube read/write functions optional for convenience
- Made the Python wrappers more pythonic (e.g., avoid C++-style passing objects as parameters which are modified in place)
- Implemented alternative Python class constructors using boost::python::make_constructor rather than with external non-class functions
- The Python wrappers taking a sequence of Point3D now take a sequence of sequences, such that the output of Conformer.GetPositions() can be passed
- Made the Python wrapper sequence parsing more robust
- Removed duplicated code from Python wrappers
* - avoid an unnecessary copy
* progress
* works
* more cleanup
* all tests pass
* changes in response to review
---------
Co-authored-by: dfhahn <dfhahn@users.noreply.github.com>
Co-authored-by: ptosco <paolo.tosco@novartis.com>
129 lines
5.3 KiB
C++
Executable File
129 lines
5.3 KiB
C++
Executable File
//
|
|
// Copyright (c) 2014-2024, Novartis Institutes for BioMedical Research and
|
|
// other RDKit contributors
|
|
//
|
|
// @@ 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.
|
|
//
|
|
#include <boost/python.hpp>
|
|
#include <RDBoost/Wrap.h>
|
|
#include <RDGeneral/types.h>
|
|
#include <RDGeneral/Invariant.h>
|
|
#include <DataStructs/RealValueVect.h>
|
|
#include <Geometry/point.h>
|
|
#include <Geometry/UniformRealValueGrid3D.h>
|
|
#include <Geometry/GridUtils.h>
|
|
namespace python = boost::python;
|
|
|
|
using namespace RDKit;
|
|
|
|
namespace RDGeom {
|
|
struct urvg3d_pickle_suite : rdkit_pickle_suite {
|
|
static python::tuple getinitargs(const UniformRealValueGrid3D &self) {
|
|
auto res = self.toString();
|
|
python::object retval(
|
|
python::handle<>(PyBytes_FromStringAndSize(res.c_str(), res.length())));
|
|
return python::make_tuple(retval);
|
|
}
|
|
};
|
|
|
|
UniformRealValueGrid3D *makeUniformRealValueGrid3D(
|
|
double dimX, double dimY, double dimZ, double spacing = 0.5,
|
|
const Point3D *offSet = nullptr) {
|
|
UniformRealValueGrid3D *grd =
|
|
new UniformRealValueGrid3D(dimX, dimY, dimZ, spacing, offSet);
|
|
return grd;
|
|
}
|
|
|
|
double getValPoint(const UniformRealValueGrid3D &grid, const Point3D &pt) {
|
|
return grid.getVal(pt);
|
|
}
|
|
|
|
double getValIndex(const UniformRealValueGrid3D &grid, unsigned int id) {
|
|
return grid.getVal(id);
|
|
}
|
|
|
|
void setValIndex(UniformRealValueGrid3D &grid, unsigned int id, double val) {
|
|
grid.setVal(id, val);
|
|
}
|
|
|
|
void setValPoint(UniformRealValueGrid3D &grid, const Point3D &pt, double val) {
|
|
grid.setVal(pt, val);
|
|
}
|
|
|
|
python::tuple getGridIndicesWrap(const UniformRealValueGrid3D &grid,
|
|
unsigned int idx) {
|
|
unsigned int xi, yi, zi;
|
|
grid.getGridIndices(idx, xi, yi, zi);
|
|
return python::make_tuple(xi, yi, zi);
|
|
}
|
|
|
|
std::string urvGridClassDoc =
|
|
"Class to represent a uniform three-dimensional\n\
|
|
cubic grid. Each grid point can store a floating point value. \n";
|
|
|
|
struct urvGrid3D_wrapper {
|
|
static void wrap() {
|
|
python::class_<UniformRealValueGrid3D>(
|
|
"UniformRealValueGrid3D", urvGridClassDoc.c_str(),
|
|
python::init<std::string>("Pickle constructor"))
|
|
.def(python::init<>("Default constructor"))
|
|
.def(python::init<RDGeom::UniformRealValueGrid3D>("Copy constructor"))
|
|
.def("__init__",
|
|
python::make_constructor(
|
|
makeUniformRealValueGrid3D, python::default_call_policies(),
|
|
(python::arg("dimX"), python::arg("dimY"), python::arg("dimZ"),
|
|
python::arg("spacing") = 0.5,
|
|
python::arg("offSet") = python::object())),
|
|
"Constructor")
|
|
.def("GetGridPointIndex", &UniformRealValueGrid3D::getGridPointIndex,
|
|
"Get the index to the grid point closest to the specified point")
|
|
.def(
|
|
"GetGridIndex", &UniformRealValueGrid3D::getGridIndex,
|
|
"Get the index to the grid point with the three integer indices provided")
|
|
.def("GetGridIndices", &getGridIndicesWrap,
|
|
"Returns the integer indices of the grid index provided.")
|
|
.def("GetValPoint", getValPoint,
|
|
"Get the value at the closest grid point")
|
|
.def("GetVal", getValIndex, "Get the value at the specified grid point")
|
|
.def("SetVal", setValIndex, "Set the value at the specified grid point")
|
|
.def("SetValPoint", setValPoint,
|
|
"Set the value at grid point closest to the specified point")
|
|
.def("GetGridPointLoc", &UniformRealValueGrid3D::getGridPointLoc,
|
|
"Get the location of the specified grid point")
|
|
.def("GetSize", &UniformRealValueGrid3D::getSize,
|
|
"Get the size of the grid (number of grid points)")
|
|
.def("GetNumX", &UniformRealValueGrid3D::getNumX,
|
|
"Get the number of grid points along x-axis")
|
|
.def("GetNumY", &UniformRealValueGrid3D::getNumY,
|
|
"Get the number of grid points along y-axis")
|
|
.def("GetNumZ", &UniformRealValueGrid3D::getNumZ,
|
|
"Get the number of grid points along z-axis")
|
|
.def("GetOffset", &UniformRealValueGrid3D::getOffset,
|
|
python::return_value_policy<python::copy_const_reference>(),
|
|
"Get the location of the center of the grid")
|
|
.def("GetSpacing", &UniformRealValueGrid3D::getSpacing,
|
|
"Get the grid spacing")
|
|
.def("GetOccupancyVect", &UniformRealValueGrid3D::getOccupancyVect,
|
|
python::return_value_policy<python::reference_existing_object>(),
|
|
"Get the occupancy vector for the grid")
|
|
.def("CompareVectors", &UniformRealValueGrid3D::compareVectors,
|
|
"Compare the vector values between two grid objects.")
|
|
.def("CompareParams", &UniformRealValueGrid3D::compareParams,
|
|
"Compare the parameters between two grid object.")
|
|
.def("CompareGrids", &UniformRealValueGrid3D::compareGrids,
|
|
"Compare the parameters and values between two grid objects.")
|
|
.def(python::self &= python::self)
|
|
.def(python::self |= python::self)
|
|
.def(python::self += python::self)
|
|
.def(python::self -= python::self)
|
|
.def_pickle(RDGeom::urvg3d_pickle_suite());
|
|
}
|
|
};
|
|
} // namespace RDGeom
|
|
|
|
void wrap_uniformrealvalueGrid() { RDGeom::urvGrid3D_wrapper::wrap(); }
|