mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
Fix/urange check (#1506)
* Fixes atom documentation * Fixes #1461 This is a complicated one. Basically URANGE_CHECK when used on unsigned integers has a problem when the size of the range it’s checking is 0. The standard operations is to check URANGE(num, size-1) Which (for unsigned integers) obviously rolls over. This fixes all usage cases to be URANGE(num+1, size) And fixes the bugs found. (addBond and the mmff tests) * Fixes #1461 - Updates URANGE_CHECK to be 0<=x<hi
This commit is contained in:
committed by
Greg Landrum
parent
bbd615497a
commit
7488840ac4
@@ -334,8 +334,8 @@ class HierarchCatalog : public Catalog<entryType, paramType> {
|
||||
*/
|
||||
void addEdge(unsigned int id1, unsigned int id2) {
|
||||
unsigned int nents = getNumEntries();
|
||||
URANGE_CHECK(id1, nents - 1);
|
||||
URANGE_CHECK(id2, nents - 1);
|
||||
URANGE_CHECK(id1, nents);
|
||||
URANGE_CHECK(id2, nents);
|
||||
// FIX: if we boost::setS for the edgeList BGL will
|
||||
// do the checking for duplicity (parallel edges)
|
||||
// But for reasons unknown setS results in compile
|
||||
@@ -352,7 +352,7 @@ class HierarchCatalog : public Catalog<entryType, paramType> {
|
||||
//------------------------------------
|
||||
//! returns a pointer to our entry with a particular index
|
||||
const entryType *getEntryWithIdx(unsigned int idx) const {
|
||||
URANGE_CHECK(idx, getNumEntries() - 1);
|
||||
URANGE_CHECK(idx, getNumEntries());
|
||||
int vd = static_cast<int>(boost::vertex(idx, d_graph));
|
||||
typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
|
||||
pMap = boost::get(vertex_entry_t(), d_graph);
|
||||
@@ -362,7 +362,7 @@ class HierarchCatalog : public Catalog<entryType, paramType> {
|
||||
//------------------------------------
|
||||
//! returns a pointer to our entry with a particular bit ID
|
||||
const entryType *getEntryWithBitId(unsigned int idx) const {
|
||||
URANGE_CHECK(idx, this->getFPLength() - 1);
|
||||
URANGE_CHECK(idx, this->getFPLength());
|
||||
typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
|
||||
pMap = boost::get(vertex_entry_t(), d_graph);
|
||||
const entryType *res = NULL;
|
||||
@@ -379,7 +379,7 @@ class HierarchCatalog : public Catalog<entryType, paramType> {
|
||||
//------------------------------------
|
||||
//! returns the index of the entry with a particular bit ID
|
||||
int getIdOfEntryWithBitId(unsigned int idx) const {
|
||||
URANGE_CHECK(idx, this->getFPLength() - 1);
|
||||
URANGE_CHECK(idx, this->getFPLength());
|
||||
typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
|
||||
pMap = boost::get(vertex_entry_t(), d_graph);
|
||||
int res = -1;
|
||||
|
||||
@@ -34,8 +34,8 @@ class BoundsMatrix : public RDNumeric::SquareMatrix<double> {
|
||||
|
||||
//! Get the upper bound between points i and j
|
||||
inline double getUpperBound(unsigned int i, unsigned int j) const {
|
||||
URANGE_CHECK(i, d_nRows - 1);
|
||||
URANGE_CHECK(j, d_nCols - 1);
|
||||
URANGE_CHECK(i, d_nRows);
|
||||
URANGE_CHECK(j, d_nCols);
|
||||
|
||||
if (i < j) {
|
||||
return getVal(i, j);
|
||||
@@ -46,8 +46,8 @@ class BoundsMatrix : public RDNumeric::SquareMatrix<double> {
|
||||
|
||||
//! Set the lower bound between points i and j
|
||||
inline void setUpperBound(unsigned int i, unsigned int j, double val) {
|
||||
URANGE_CHECK(i, d_nRows - 1);
|
||||
URANGE_CHECK(j, d_nCols - 1);
|
||||
URANGE_CHECK(i, d_nRows);
|
||||
URANGE_CHECK(j, d_nCols);
|
||||
CHECK_INVARIANT(val >= 0.0, "Negative upper bound");
|
||||
if (i < j) {
|
||||
setVal(i, j, val);
|
||||
@@ -67,8 +67,8 @@ class BoundsMatrix : public RDNumeric::SquareMatrix<double> {
|
||||
|
||||
//! Set the lower bound between points i and j
|
||||
inline void setLowerBound(unsigned int i, unsigned int j, double val) {
|
||||
URANGE_CHECK(i, d_nRows - 1);
|
||||
URANGE_CHECK(j, d_nCols - 1);
|
||||
URANGE_CHECK(i, d_nRows);
|
||||
URANGE_CHECK(j, d_nCols);
|
||||
CHECK_INVARIANT(val >= 0.0, "Negative lower bound");
|
||||
if (i < j) {
|
||||
setVal(j, i, val);
|
||||
@@ -88,8 +88,8 @@ class BoundsMatrix : public RDNumeric::SquareMatrix<double> {
|
||||
|
||||
//! Get the lower bound between points i and j
|
||||
inline double getLowerBound(unsigned int i, unsigned int j) const {
|
||||
URANGE_CHECK(i, d_nRows - 1);
|
||||
URANGE_CHECK(j, d_nCols - 1);
|
||||
URANGE_CHECK(i, d_nRows);
|
||||
URANGE_CHECK(j, d_nCols);
|
||||
|
||||
if (i < j) {
|
||||
return getVal(j, i);
|
||||
|
||||
@@ -14,10 +14,10 @@ ChiralViolationContrib::ChiralViolationContrib(ForceFields::ForceField *owner,
|
||||
PRECONDITION(owner, "bad owner");
|
||||
PRECONDITION(cset, "bad chiral set")
|
||||
|
||||
URANGE_CHECK(cset->d_idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(cset->d_idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(cset->d_idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(cset->d_idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(cset->d_idx1, owner->positions().size());
|
||||
URANGE_CHECK(cset->d_idx2, owner->positions().size());
|
||||
URANGE_CHECK(cset->d_idx3, owner->positions().size());
|
||||
URANGE_CHECK(cset->d_idx4, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ DistViolationContrib::DistViolationContrib(ForceFields::ForceField *owner,
|
||||
double ub, double lb,
|
||||
double weight) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_end1Idx = idx1;
|
||||
|
||||
@@ -92,8 +92,8 @@ ForceField::ForceField(const ForceField &other)
|
||||
|
||||
double ForceField::distance(unsigned int i, unsigned int j, double *pos) {
|
||||
PRECONDITION(df_init, "not initialized");
|
||||
URANGE_CHECK(i, d_numPoints - 1);
|
||||
URANGE_CHECK(j, d_numPoints - 1);
|
||||
URANGE_CHECK(i, d_numPoints);
|
||||
URANGE_CHECK(j, d_numPoints);
|
||||
if (j < i) {
|
||||
int tmp = j;
|
||||
j = i;
|
||||
@@ -133,8 +133,8 @@ double ForceField::distance(unsigned int i, unsigned int j, double *pos) {
|
||||
|
||||
double ForceField::distance(unsigned int i, unsigned int j, double *pos) const {
|
||||
PRECONDITION(df_init, "not initialized");
|
||||
URANGE_CHECK(i, d_numPoints - 1);
|
||||
URANGE_CHECK(j, d_numPoints - 1);
|
||||
URANGE_CHECK(i, d_numPoints);
|
||||
URANGE_CHECK(j, d_numPoints);
|
||||
if (j < i) {
|
||||
int tmp = j;
|
||||
j = i;
|
||||
|
||||
@@ -92,9 +92,9 @@ AngleBendContrib::AngleBendContrib(ForceField *owner, unsigned int idx1,
|
||||
PRECONDITION(owner, "bad owner");
|
||||
PRECONDITION(((idx1 != idx2) && (idx2 != idx3) && (idx1 != idx3)),
|
||||
"degenerate points");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -41,9 +41,9 @@ AngleConstraintContrib::AngleConstraintContrib(
|
||||
ForceField *owner, unsigned int idx1, unsigned int idx2, unsigned int idx3,
|
||||
double minAngleDeg, double maxAngleDeg, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
PRECONDITION(maxAngleDeg >= minAngleDeg, "allowedDeltaDeg must be >= 0.0");
|
||||
_pretreatAngles(minAngleDeg, maxAngleDeg);
|
||||
|
||||
@@ -61,9 +61,9 @@ AngleConstraintContrib::AngleConstraintContrib(
|
||||
bool relative, double minAngleDeg, double maxAngleDeg, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx1, pos.size() - 1);
|
||||
URANGE_CHECK(idx2, pos.size() - 1);
|
||||
URANGE_CHECK(idx3, pos.size() - 1);
|
||||
URANGE_CHECK(idx1, pos.size());
|
||||
URANGE_CHECK(idx2, pos.size());
|
||||
URANGE_CHECK(idx3, pos.size());
|
||||
PRECONDITION(maxAngleDeg >= minAngleDeg, "allowedDeltaDeg must be >= 0.0");
|
||||
|
||||
double angle = 0.0;
|
||||
|
||||
@@ -52,8 +52,8 @@ BondStretchContrib::BondStretchContrib(ForceField *owner,
|
||||
const unsigned int idx2,
|
||||
const MMFFBond *mmffBondParams) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -21,8 +21,8 @@ DistanceConstraintContrib::DistanceConstraintContrib(
|
||||
ForceField *owner, unsigned int idx1, unsigned int idx2, double minLen,
|
||||
double maxLen, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
PRECONDITION(maxLen >= minLen, "bad bounds");
|
||||
|
||||
dp_forceField = owner;
|
||||
@@ -38,8 +38,8 @@ DistanceConstraintContrib::DistanceConstraintContrib(
|
||||
double minLen, double maxLen, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx1, pos.size() - 1);
|
||||
URANGE_CHECK(idx2, pos.size() - 1);
|
||||
URANGE_CHECK(idx1, pos.size());
|
||||
URANGE_CHECK(idx2, pos.size());
|
||||
PRECONDITION(maxLen >= minLen, "bad bounds");
|
||||
|
||||
double dist = 0.0;
|
||||
|
||||
@@ -96,8 +96,8 @@ VdWContrib::VdWContrib(ForceField *owner, unsigned int idx1, unsigned int idx2,
|
||||
const MMFFVdWRijstarEps *mmffVdWConstants) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
PRECONDITION(mmffVdWConstants, "bad MMFFVdW parameters");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
@@ -153,8 +153,8 @@ EleContrib::EleContrib(ForceField *owner, unsigned int idx1, unsigned int idx2,
|
||||
double chargeTerm, boost::uint8_t dielModel,
|
||||
bool is1_4) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -58,10 +58,10 @@ OopBendContrib::OopBendContrib(ForceField *owner, unsigned int idx1,
|
||||
PRECONDITION((idx1 != idx2) && (idx1 != idx3) && (idx1 != idx4) &&
|
||||
(idx2 != idx3) && (idx2 != idx4) && (idx3 != idx4),
|
||||
"degenerate points");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
URANGE_CHECK(idx4, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -23,7 +23,7 @@ PositionConstraintContrib::PositionConstraintContrib(ForceField *owner,
|
||||
double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx, pos.size() - 1);
|
||||
URANGE_CHECK(idx, pos.size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_atIdx = idx;
|
||||
|
||||
@@ -48,9 +48,9 @@ StretchBendContrib::StretchBendContrib(
|
||||
PRECONDITION(owner, "bad owner");
|
||||
PRECONDITION(((idx1 != idx2) && (idx2 != idx3) && (idx1 != idx3)),
|
||||
"degenerate points");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -99,10 +99,10 @@ TorsionAngleContrib::TorsionAngleContrib(ForceField *owner, unsigned int idx1,
|
||||
PRECONDITION((idx1 != idx2) && (idx1 != idx3) && (idx1 != idx4) &&
|
||||
(idx2 != idx3) && (idx2 != idx4) && (idx3 != idx4),
|
||||
"degenerate points");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
URANGE_CHECK(idx4, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -37,10 +37,10 @@ TorsionConstraintContrib::TorsionConstraintContrib(
|
||||
unsigned int idx4, double minDihedralDeg, double maxDihedralDeg,
|
||||
double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
URANGE_CHECK(idx4, owner->positions().size());
|
||||
PRECONDITION((!(maxDihedralDeg < minDihedralDeg)) &&
|
||||
((maxDihedralDeg - minDihedralDeg) < 360.0),
|
||||
"bad bounds");
|
||||
@@ -62,10 +62,10 @@ TorsionConstraintContrib::TorsionConstraintContrib(
|
||||
double maxDihedralDeg, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx1, pos.size() - 1);
|
||||
URANGE_CHECK(idx2, pos.size() - 1);
|
||||
URANGE_CHECK(idx3, pos.size() - 1);
|
||||
URANGE_CHECK(idx4, pos.size() - 1);
|
||||
URANGE_CHECK(idx1, pos.size());
|
||||
URANGE_CHECK(idx2, pos.size());
|
||||
URANGE_CHECK(idx3, pos.size());
|
||||
URANGE_CHECK(idx4, pos.size());
|
||||
PRECONDITION((!(maxDihedralDeg < minDihedralDeg)) &&
|
||||
((maxDihedralDeg - minDihedralDeg) < 360.0),
|
||||
"bad bounds");
|
||||
|
||||
@@ -76,9 +76,9 @@ AngleBendContrib::AngleBendContrib(ForceField *owner, unsigned int idx1,
|
||||
PRECONDITION(at3Params, "bad params pointer");
|
||||
PRECONDITION((idx1 != idx2 && idx2 != idx3 && idx1 != idx3),
|
||||
"degenerate points");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
// the following is a hack to get decent geometries
|
||||
// with 3- and 4-membered rings incorporating sp2 atoms
|
||||
double theta0 = at2Params->theta0;
|
||||
|
||||
@@ -41,9 +41,9 @@ AngleConstraintContrib::AngleConstraintContrib(
|
||||
ForceField *owner, unsigned int idx1, unsigned int idx2, unsigned int idx3,
|
||||
double minAngleDeg, double maxAngleDeg, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
PRECONDITION(maxAngleDeg >= minAngleDeg, "allowedDeltaDeg must be >= 0.0");
|
||||
_pretreatAngles(minAngleDeg, maxAngleDeg);
|
||||
|
||||
@@ -61,9 +61,9 @@ AngleConstraintContrib::AngleConstraintContrib(
|
||||
bool relative, double minAngleDeg, double maxAngleDeg, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx1, pos.size() - 1);
|
||||
URANGE_CHECK(idx2, pos.size() - 1);
|
||||
URANGE_CHECK(idx3, pos.size() - 1);
|
||||
URANGE_CHECK(idx1, pos.size());
|
||||
URANGE_CHECK(idx2, pos.size());
|
||||
URANGE_CHECK(idx3, pos.size());
|
||||
PRECONDITION(maxAngleDeg >= minAngleDeg, "allowedDeltaDeg must be >= 0.0");
|
||||
|
||||
double angle = 0.0;
|
||||
|
||||
@@ -54,8 +54,8 @@ BondStretchContrib::BondStretchContrib(ForceField *owner, unsigned int idx1,
|
||||
PRECONDITION(owner, "bad owner");
|
||||
PRECONDITION(end1Params, "bad params pointer");
|
||||
PRECONDITION(end2Params, "bad params pointer");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_end1Idx = idx1;
|
||||
|
||||
@@ -21,8 +21,8 @@ DistanceConstraintContrib::DistanceConstraintContrib(
|
||||
ForceField *owner, unsigned int idx1, unsigned int idx2, double minLen,
|
||||
double maxLen, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
PRECONDITION(maxLen >= minLen, "bad bounds");
|
||||
|
||||
dp_forceField = owner;
|
||||
@@ -38,8 +38,8 @@ DistanceConstraintContrib::DistanceConstraintContrib(
|
||||
double minLen, double maxLen, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx1, pos.size() - 1);
|
||||
URANGE_CHECK(idx2, pos.size() - 1);
|
||||
URANGE_CHECK(idx1, pos.size());
|
||||
URANGE_CHECK(idx2, pos.size());
|
||||
PRECONDITION(maxLen >= minLen, "bad bounds");
|
||||
|
||||
double dist = 0.0;
|
||||
|
||||
@@ -91,10 +91,10 @@ InversionContrib::InversionContrib(ForceField *owner, unsigned int idx1,
|
||||
unsigned int idx4, int at2AtomicNum,
|
||||
bool isCBoundToO, double oobForceScalingFactor) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
URANGE_CHECK(idx4, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -35,8 +35,8 @@ vdWContrib::vdWContrib(ForceField *owner, unsigned int idx1, unsigned int idx2,
|
||||
PRECONDITION(owner, "bad owner");
|
||||
PRECONDITION(at1Params, "bad params pointer");
|
||||
PRECONDITION(at2Params, "bad params pointer");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -23,7 +23,7 @@ PositionConstraintContrib::PositionConstraintContrib(ForceField *owner,
|
||||
double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx, pos.size() - 1);
|
||||
URANGE_CHECK(idx, pos.size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_atIdx = idx;
|
||||
|
||||
@@ -94,10 +94,10 @@ TorsionAngleContrib::TorsionAngleContrib(
|
||||
PRECONDITION((idx1 != idx2 && idx1 != idx3 && idx1 != idx4 && idx2 != idx3 &&
|
||||
idx2 != idx4 && idx3 != idx4),
|
||||
"degenerate points");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
URANGE_CHECK(idx4, owner->positions().size());
|
||||
|
||||
dp_forceField = owner;
|
||||
d_at1Idx = idx1;
|
||||
|
||||
@@ -37,10 +37,10 @@ TorsionConstraintContrib::TorsionConstraintContrib(
|
||||
unsigned int idx4, double minDihedralDeg, double maxDihedralDeg,
|
||||
double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
URANGE_CHECK(idx4, owner->positions().size());
|
||||
PRECONDITION((!(maxDihedralDeg < minDihedralDeg)) &&
|
||||
((maxDihedralDeg - minDihedralDeg) < 360.0),
|
||||
"bad bounds");
|
||||
@@ -62,10 +62,10 @@ TorsionConstraintContrib::TorsionConstraintContrib(
|
||||
double maxDihedralDeg, double forceConst) {
|
||||
PRECONDITION(owner, "bad owner");
|
||||
const RDGeom::PointPtrVect &pos = owner->positions();
|
||||
URANGE_CHECK(idx1, pos.size() - 1);
|
||||
URANGE_CHECK(idx2, pos.size() - 1);
|
||||
URANGE_CHECK(idx3, pos.size() - 1);
|
||||
URANGE_CHECK(idx4, pos.size() - 1);
|
||||
URANGE_CHECK(idx1, pos.size());
|
||||
URANGE_CHECK(idx2, pos.size());
|
||||
URANGE_CHECK(idx3, pos.size());
|
||||
URANGE_CHECK(idx4, pos.size());
|
||||
PRECONDITION((!(maxDihedralDeg < minDihedralDeg)) &&
|
||||
((maxDihedralDeg - minDihedralDeg) < 360.0),
|
||||
"bad bounds");
|
||||
|
||||
@@ -82,12 +82,12 @@ unsigned int Bond::getOtherAtomIdx(const unsigned int thisIdx) const {
|
||||
}
|
||||
|
||||
void Bond::setBeginAtomIdx(unsigned int what) {
|
||||
if (dp_mol) URANGE_CHECK(what, getOwningMol().getNumAtoms() - 1);
|
||||
if (dp_mol) URANGE_CHECK(what, getOwningMol().getNumAtoms());
|
||||
d_beginAtomIdx = what;
|
||||
};
|
||||
|
||||
void Bond::setEndAtomIdx(unsigned int what) {
|
||||
if (dp_mol) URANGE_CHECK(what, getOwningMol().getNumAtoms() - 1);
|
||||
if (dp_mol) URANGE_CHECK(what, getOwningMol().getNumAtoms());
|
||||
d_endAtomIdx = what;
|
||||
};
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ void recurseOverReactantCombinations(
|
||||
VectVectMatchVectType &matchesPerProduct, unsigned int level,
|
||||
VectMatchVectType combination) {
|
||||
unsigned int nReactants = matchesByReactant.size();
|
||||
URANGE_CHECK(level, nReactants - 1);
|
||||
URANGE_CHECK(level, nReactants);
|
||||
PRECONDITION(combination.size() == nReactants, "bad combination size");
|
||||
for (VectMatchVectType::const_iterator reactIt =
|
||||
matchesByReactant[level].begin();
|
||||
|
||||
@@ -50,7 +50,7 @@ const RDGeom::Point3D &Conformer::getAtomPos(unsigned int atomId) const {
|
||||
if (dp_mol) {
|
||||
PRECONDITION(dp_mol->getNumAtoms() == d_positions.size(), "");
|
||||
}
|
||||
URANGE_CHECK(atomId, d_positions.size() - 1);
|
||||
URANGE_CHECK(atomId, d_positions.size());
|
||||
return d_positions[atomId];
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ RDGeom::Point3D &Conformer::getAtomPos(unsigned int atomId) {
|
||||
if (dp_mol) {
|
||||
PRECONDITION(dp_mol->getNumAtoms() == d_positions.size(), "");
|
||||
}
|
||||
URANGE_CHECK(atomId, d_positions.size() - 1);
|
||||
URANGE_CHECK(atomId, d_positions.size());
|
||||
return d_positions[atomId];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ void getNbrAtomAndBondIds(unsigned int aid, const RDKit::ROMol *mol,
|
||||
RDKit::INT_VECT &aids, RDKit::INT_VECT &bids) {
|
||||
CHECK_INVARIANT(mol, "");
|
||||
unsigned int na = mol->getNumAtoms();
|
||||
URANGE_CHECK(aid, na - 1);
|
||||
URANGE_CHECK(aid, na);
|
||||
|
||||
RDKit::ROMol::ADJ_ITER nbrIdx, endNbrs;
|
||||
boost::tie(nbrIdx, endNbrs) = mol->getAtomNeighbors(mol->getAtomWithIdx(aid));
|
||||
|
||||
@@ -168,7 +168,7 @@ void ParseOldAtomList(RWMol *mol, const std::string &text, unsigned int line) {
|
||||
throw FileParseException(errout.str());
|
||||
}
|
||||
|
||||
URANGE_CHECK(idx, mol->getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx, mol->getNumAtoms());
|
||||
QueryAtom a(*(mol->getAtomWithIdx(idx)));
|
||||
|
||||
ATOM_OR_QUERY *q = new ATOM_OR_QUERY;
|
||||
@@ -785,7 +785,7 @@ void ParseNewAtomList(RWMol *mol, const std::string &text, unsigned int line) {
|
||||
<< line;
|
||||
throw FileParseException(errout.str());
|
||||
}
|
||||
URANGE_CHECK(idx, mol->getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx, mol->getNumAtoms());
|
||||
QueryAtom *a = 0;
|
||||
|
||||
int nQueries;
|
||||
@@ -972,7 +972,7 @@ void ParseAtomAlias(RWMol *mol, std::string text, const std::string &nextLine,
|
||||
<< line;
|
||||
throw FileParseException(errout.str());
|
||||
}
|
||||
URANGE_CHECK(idx, mol->getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx, mol->getNumAtoms());
|
||||
Atom *at = mol->getAtomWithIdx(idx);
|
||||
at->setProp(common_properties::molFileAlias, nextLine);
|
||||
};
|
||||
@@ -991,7 +991,7 @@ void ParseAtomValue(RWMol *mol, std::string text, unsigned int line) {
|
||||
<< line;
|
||||
throw FileParseException(errout.str());
|
||||
}
|
||||
URANGE_CHECK(idx, mol->getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx, mol->getNumAtoms());
|
||||
Atom *at = mol->getAtomWithIdx(idx);
|
||||
at->setProp(common_properties::molFileValue,
|
||||
text.substr(7, text.length() - 7));
|
||||
|
||||
@@ -57,10 +57,10 @@ TorsionAngleContribM6::TorsionAngleContribM6(
|
||||
PRECONDITION((idx1 != idx2) && (idx1 != idx3) && (idx1 != idx4) &&
|
||||
(idx2 != idx3) && (idx2 != idx4) && (idx3 != idx4),
|
||||
"degenerate points");
|
||||
URANGE_CHECK(idx1, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx2, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx3, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx4, owner->positions().size() - 1);
|
||||
URANGE_CHECK(idx1, owner->positions().size());
|
||||
URANGE_CHECK(idx2, owner->positions().size());
|
||||
URANGE_CHECK(idx3, owner->positions().size());
|
||||
URANGE_CHECK(idx4, owner->positions().size());
|
||||
};
|
||||
|
||||
double TorsionAngleContribM6::getEnergy(double *pos) const {
|
||||
|
||||
@@ -63,17 +63,17 @@ class MMFFMolProperties {
|
||||
const ForceFields::MMFF::MMFFBond *getMMFFBondStretchEmpiricalRuleParams(
|
||||
const ROMol &mol, const Bond *bond);
|
||||
boost::uint8_t getMMFFAtomType(const unsigned int idx) {
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size() - 1);
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size());
|
||||
|
||||
return this->d_MMFFAtomPropertiesPtrVect[idx]->mmffAtomType;
|
||||
};
|
||||
double getMMFFFormalCharge(const unsigned int idx) {
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size() - 1);
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size());
|
||||
|
||||
return this->d_MMFFAtomPropertiesPtrVect[idx]->mmffFormalCharge;
|
||||
};
|
||||
double getMMFFPartialCharge(const unsigned int idx) {
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size() - 1);
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size());
|
||||
|
||||
return this->d_MMFFAtomPropertiesPtrVect[idx]->mmffPartialCharge;
|
||||
};
|
||||
@@ -148,12 +148,12 @@ class MMFFMolProperties {
|
||||
void setMMFFHeavyAtomType(const RingMembershipSize &rmSize, const Atom *atom);
|
||||
void setMMFFHydrogenType(const Atom *atom);
|
||||
void setMMFFFormalCharge(const unsigned int idx, const double fChg) {
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size() - 1);
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size());
|
||||
|
||||
this->d_MMFFAtomPropertiesPtrVect[idx]->mmffFormalCharge = fChg;
|
||||
};
|
||||
void setMMFFPartialCharge(const unsigned int idx, const double pChg) {
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size() - 1);
|
||||
URANGE_CHECK(idx, this->d_MMFFAtomPropertiesPtrVect.size());
|
||||
|
||||
this->d_MMFFAtomPropertiesPtrVect[idx]->mmffPartialCharge = pChg;
|
||||
};
|
||||
|
||||
@@ -162,6 +162,11 @@ void testMMFFBuilder1() {
|
||||
TEST_ASSERT(mmffMolProperties);
|
||||
TEST_ASSERT(mmffMolProperties->isValid());
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&(conf->getAtomPos(i)));
|
||||
}
|
||||
|
||||
MMFF::Tools::addBonds(*mol, mmffMolProperties, field);
|
||||
|
||||
TEST_ASSERT(field->contribs().size() == 3);
|
||||
@@ -207,6 +212,11 @@ void testMMFFBuilder1() {
|
||||
TEST_ASSERT(mmffMolProperties);
|
||||
TEST_ASSERT(mmffMolProperties->isValid());
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&(conf2->getAtomPos(i)));
|
||||
}
|
||||
|
||||
MMFF::Tools::addBonds(*mol, mmffMolProperties, field);
|
||||
|
||||
TEST_ASSERT(field->contribs().size() == 3);
|
||||
@@ -240,6 +250,11 @@ void testMMFFBuilder1() {
|
||||
TEST_ASSERT(mmffMolProperties->isValid());
|
||||
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&(conf3->getAtomPos(i)));
|
||||
}
|
||||
|
||||
MMFF::Tools::addBonds(*mol, mmffMolProperties, field);
|
||||
|
||||
TEST_ASSERT(field->contribs().size() == 1);
|
||||
@@ -259,6 +274,9 @@ void testMMFFBuilder1() {
|
||||
|
||||
mol2 = MolOps::addHs(*mol);
|
||||
TEST_ASSERT(mol2->getNumAtoms() == 6);
|
||||
Conformer *conf4 = new Conformer(mol2->getNumAtoms());
|
||||
cid = static_cast<int>(mol2->addConformer(conf4, true));
|
||||
|
||||
delete field;
|
||||
delete mmffMolProperties;
|
||||
|
||||
@@ -267,6 +285,11 @@ void testMMFFBuilder1() {
|
||||
TEST_ASSERT(mmffMolProperties->isValid());
|
||||
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol2->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&(conf4->getAtomPos(i)));
|
||||
}
|
||||
|
||||
MMFF::Tools::addBonds(*mol2, mmffMolProperties, field);
|
||||
TEST_ASSERT(field->contribs().size() == 5);
|
||||
|
||||
@@ -535,9 +558,14 @@ void testSFIssue1653802() {
|
||||
MMFF::MMFFMolProperties *mmffMolProperties =
|
||||
new MMFF::MMFFMolProperties(*mol);
|
||||
TEST_ASSERT(mmffMolProperties);
|
||||
|
||||
|
||||
boost::shared_array<boost::uint8_t> nbrMat;
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&((mol->getConformer().getAtomPos(i))));
|
||||
}
|
||||
|
||||
MMFF::Tools::addBonds(*mol, mmffMolProperties, field);
|
||||
TEST_ASSERT(field->contribs().size() == 8);
|
||||
|
||||
|
||||
@@ -220,6 +220,11 @@ void testUFFBuilder1() {
|
||||
TEST_ASSERT(foundAll);
|
||||
TEST_ASSERT(types.size() == mol->getNumAtoms());
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&((conf->getAtomPos(i))));
|
||||
}
|
||||
|
||||
UFF::Tools::addBonds(*mol, types, field);
|
||||
|
||||
TEST_ASSERT(field->contribs().size() == 3);
|
||||
@@ -260,6 +265,11 @@ void testUFFBuilder1() {
|
||||
TEST_ASSERT(foundAll);
|
||||
TEST_ASSERT(types.size() == mol->getNumAtoms());
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&(conf2->getAtomPos(i)));
|
||||
}
|
||||
|
||||
UFF::Tools::addBonds(*mol, types, field);
|
||||
|
||||
TEST_ASSERT(field->contribs().size() == 3);
|
||||
@@ -288,6 +298,11 @@ void testUFFBuilder1() {
|
||||
TEST_ASSERT(types.size() == mol->getNumAtoms());
|
||||
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&(conf3->getAtomPos(i)));
|
||||
}
|
||||
|
||||
UFF::Tools::addBonds(*mol, types, field);
|
||||
|
||||
TEST_ASSERT(field->contribs().size() == 1);
|
||||
@@ -310,8 +325,15 @@ void testUFFBuilder1() {
|
||||
boost::tie(types, foundAll) = UFF::getAtomTypes(*mol2);
|
||||
TEST_ASSERT(foundAll);
|
||||
TEST_ASSERT(types.size() == mol2->getNumAtoms());
|
||||
Conformer *conf4 = new Conformer(mol2->getNumAtoms());
|
||||
cid = static_cast<int>(mol2->addConformer(conf4, true));
|
||||
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol2->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&(conf4->getAtomPos(i)));
|
||||
}
|
||||
|
||||
UFF::Tools::addBonds(*mol2, types, field);
|
||||
TEST_ASSERT(field->contribs().size() == 5);
|
||||
|
||||
@@ -448,10 +470,36 @@ void testUFFBuilder2() {
|
||||
RWMol *mol = MolFileToMol(pathName + "/small1.mol", false);
|
||||
TEST_ASSERT(mol);
|
||||
MolOps::sanitizeMol(*mol);
|
||||
|
||||
UFF::AtomicParamVect types;
|
||||
bool foundAll;
|
||||
boost::shared_array<boost::uint8_t> nbrMat;
|
||||
boost::tie(types, foundAll) = UFF::getAtomTypes(*mol);
|
||||
|
||||
ForceFields::ForceField *field;
|
||||
field = new ForceFields::ForceField();
|
||||
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&((mol->getConformer().getAtomPos(i))));
|
||||
}
|
||||
|
||||
UFF::Tools::addBonds(*mol, types, field);
|
||||
nbrMat = UFF::Tools::buildNeighborMatrix(*mol);
|
||||
UFF::Tools::addAngles(*mol, types, field);
|
||||
UFF::Tools::addTorsions(*mol, types, field);
|
||||
// std::cout << field->contribs().size() << std::endl;
|
||||
UFF::Tools::addNonbonded(*mol, 0, types, field, nbrMat);
|
||||
delete field;
|
||||
|
||||
field = UFF::constructForceField(*mol);
|
||||
field->initialize();
|
||||
field->minimize();
|
||||
delete field;
|
||||
|
||||
RWMol *mol2 = new RWMol(*mol);
|
||||
|
||||
ForceFields::ForceField *field;
|
||||
field = UFF::constructForceField(*mol);
|
||||
field = UFF::constructForceField(*mol2);
|
||||
TEST_ASSERT(field);
|
||||
field->initialize();
|
||||
int needMore = field->minimize();
|
||||
@@ -788,6 +836,11 @@ void testSFIssue1653802() {
|
||||
TEST_ASSERT(foundAll);
|
||||
TEST_ASSERT(types.size() == mol->getNumAtoms());
|
||||
field = new ForceFields::ForceField();
|
||||
// add the atomic positions:
|
||||
for (unsigned int i = 0; i < mol->getNumAtoms(); ++i) {
|
||||
field->positions().push_back(&((mol->getConformer().getAtomPos(i))));
|
||||
}
|
||||
|
||||
UFF::Tools::addBonds(*mol, types, field);
|
||||
TEST_ASSERT(field->contribs().size() == 8);
|
||||
|
||||
|
||||
@@ -402,8 +402,8 @@ void _toBeMovedIdxList(const ROMol &mol, unsigned int iAtomId,
|
||||
double getBondLength(const Conformer &conf, unsigned int iAtomId,
|
||||
unsigned int jAtomId) {
|
||||
const RDGeom::POINT3D_VECT &pos = conf.getPositions();
|
||||
URANGE_CHECK(iAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(jAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(iAtomId, pos.size());
|
||||
URANGE_CHECK(jAtomId, pos.size());
|
||||
|
||||
return (pos[iAtomId] - pos[jAtomId]).length();
|
||||
}
|
||||
@@ -411,8 +411,8 @@ double getBondLength(const Conformer &conf, unsigned int iAtomId,
|
||||
void setBondLength(Conformer &conf, unsigned int iAtomId, unsigned int jAtomId,
|
||||
double value) {
|
||||
RDGeom::POINT3D_VECT &pos = conf.getPositions();
|
||||
URANGE_CHECK(iAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(jAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(iAtomId, pos.size());
|
||||
URANGE_CHECK(jAtomId, pos.size());
|
||||
ROMol &mol = conf.getOwningMol();
|
||||
Bond *bond = mol.getBondBetweenAtoms(iAtomId, jAtomId);
|
||||
if (!bond) throw ValueErrorException("atoms i and j must be bonded");
|
||||
@@ -436,9 +436,9 @@ void setBondLength(Conformer &conf, unsigned int iAtomId, unsigned int jAtomId,
|
||||
double getAngleRad(const Conformer &conf, unsigned int iAtomId,
|
||||
unsigned int jAtomId, unsigned int kAtomId) {
|
||||
const RDGeom::POINT3D_VECT &pos = conf.getPositions();
|
||||
URANGE_CHECK(iAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(jAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(kAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(iAtomId, pos.size());
|
||||
URANGE_CHECK(jAtomId, pos.size());
|
||||
URANGE_CHECK(kAtomId, pos.size());
|
||||
RDGeom::Point3D rJI = pos[iAtomId] - pos[jAtomId];
|
||||
double rJISqLength = rJI.lengthSq();
|
||||
if (rJISqLength <= 1.e-16)
|
||||
@@ -453,9 +453,9 @@ double getAngleRad(const Conformer &conf, unsigned int iAtomId,
|
||||
void setAngleRad(Conformer &conf, unsigned int iAtomId, unsigned int jAtomId,
|
||||
unsigned int kAtomId, double value) {
|
||||
RDGeom::POINT3D_VECT &pos = conf.getPositions();
|
||||
URANGE_CHECK(iAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(jAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(kAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(iAtomId, pos.size());
|
||||
URANGE_CHECK(jAtomId, pos.size());
|
||||
URANGE_CHECK(kAtomId, pos.size());
|
||||
ROMol &mol = conf.getOwningMol();
|
||||
Bond *bondJI = mol.getBondBetweenAtoms(jAtomId, iAtomId);
|
||||
if (!bondJI) throw ValueErrorException("atoms i and j must be bonded");
|
||||
@@ -501,10 +501,10 @@ double getDihedralRad(const Conformer &conf, unsigned int iAtomId,
|
||||
unsigned int jAtomId, unsigned int kAtomId,
|
||||
unsigned int lAtomId) {
|
||||
const RDGeom::POINT3D_VECT &pos = conf.getPositions();
|
||||
URANGE_CHECK(iAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(jAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(kAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(lAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(iAtomId, pos.size());
|
||||
URANGE_CHECK(jAtomId, pos.size());
|
||||
URANGE_CHECK(kAtomId, pos.size());
|
||||
URANGE_CHECK(lAtomId, pos.size());
|
||||
RDGeom::Point3D rIJ = pos[jAtomId] - pos[iAtomId];
|
||||
double rIJSqLength = rIJ.lengthSq();
|
||||
if (rIJSqLength <= 1.e-16)
|
||||
@@ -531,10 +531,10 @@ double getDihedralRad(const Conformer &conf, unsigned int iAtomId,
|
||||
void setDihedralRad(Conformer &conf, unsigned int iAtomId, unsigned int jAtomId,
|
||||
unsigned int kAtomId, unsigned int lAtomId, double value) {
|
||||
RDGeom::POINT3D_VECT &pos = conf.getPositions();
|
||||
URANGE_CHECK(iAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(jAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(kAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(lAtomId, pos.size() - 1);
|
||||
URANGE_CHECK(iAtomId, pos.size());
|
||||
URANGE_CHECK(jAtomId, pos.size());
|
||||
URANGE_CHECK(kAtomId, pos.size());
|
||||
URANGE_CHECK(lAtomId, pos.size());
|
||||
ROMol &mol = conf.getOwningMol();
|
||||
Bond *bondIJ = mol.getBondBetweenAtoms(iAtomId, jAtomId);
|
||||
if (!bondIJ) throw ValueErrorException("atoms i and j must be bonded");
|
||||
|
||||
@@ -146,7 +146,7 @@ unsigned int ROMol::getNumHeavyAtoms() const {
|
||||
|
||||
Atom *ROMol::getAtomWithIdx(unsigned int idx) {
|
||||
PRECONDITION(getNumAtoms() > 0, "no atoms");
|
||||
URANGE_CHECK(idx, getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx, getNumAtoms());
|
||||
|
||||
MolGraph::vertex_descriptor vd = boost::vertex(idx, d_graph);
|
||||
Atom *res = d_graph[vd].get();
|
||||
@@ -156,7 +156,7 @@ Atom *ROMol::getAtomWithIdx(unsigned int idx) {
|
||||
|
||||
const Atom *ROMol::getAtomWithIdx(unsigned int idx) const {
|
||||
PRECONDITION(getNumAtoms() > 0, "no atoms");
|
||||
URANGE_CHECK(idx, getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx, getNumAtoms());
|
||||
|
||||
MolGraph::vertex_descriptor vd = boost::vertex(idx, d_graph);
|
||||
const Atom *res = d_graph[vd].get();
|
||||
@@ -244,7 +244,7 @@ unsigned int ROMol::getNumBonds(bool onlyHeavy) const {
|
||||
|
||||
Bond *ROMol::getBondWithIdx(unsigned int idx) {
|
||||
PRECONDITION(getNumBonds() > 0, "no bonds");
|
||||
URANGE_CHECK(idx, getNumBonds() - 1);
|
||||
URANGE_CHECK(idx, getNumBonds());
|
||||
|
||||
BOND_ITER_PAIR bIter = getEdges();
|
||||
for (unsigned int i = 0; i < idx; i++) ++bIter.first;
|
||||
@@ -256,7 +256,7 @@ Bond *ROMol::getBondWithIdx(unsigned int idx) {
|
||||
|
||||
const Bond *ROMol::getBondWithIdx(unsigned int idx) const {
|
||||
PRECONDITION(getNumBonds() > 0, "no bonds");
|
||||
URANGE_CHECK(idx, getNumBonds() - 1);
|
||||
URANGE_CHECK(idx, getNumBonds());
|
||||
|
||||
BOND_ITER_PAIR bIter = getEdges();
|
||||
for (unsigned int i = 0; i < idx; i++) ++bIter.first;
|
||||
@@ -267,8 +267,8 @@ const Bond *ROMol::getBondWithIdx(unsigned int idx) const {
|
||||
}
|
||||
|
||||
Bond *ROMol::getBondBetweenAtoms(unsigned int idx1, unsigned int idx2) {
|
||||
URANGE_CHECK(idx1, getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx2, getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx1, getNumAtoms());
|
||||
URANGE_CHECK(idx2, getNumAtoms());
|
||||
Bond *res = 0;
|
||||
|
||||
MolGraph::edge_descriptor edge;
|
||||
@@ -283,8 +283,8 @@ Bond *ROMol::getBondBetweenAtoms(unsigned int idx1, unsigned int idx2) {
|
||||
|
||||
const Bond *ROMol::getBondBetweenAtoms(unsigned int idx1,
|
||||
unsigned int idx2) const {
|
||||
URANGE_CHECK(idx1, getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx2, getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx1, getNumAtoms());
|
||||
URANGE_CHECK(idx2, getNumAtoms());
|
||||
const Bond *res = 0;
|
||||
|
||||
MolGraph::edge_descriptor edge;
|
||||
@@ -341,8 +341,8 @@ unsigned int ROMol::addAtom(Atom::ATOM_SPTR atom_sp, bool updateLabel) {
|
||||
}
|
||||
unsigned int ROMol::addBond(Bond *bond_pin, bool takeOwnership) {
|
||||
PRECONDITION(bond_pin, "null bond passed in");
|
||||
URANGE_CHECK(bond_pin->getBeginAtomIdx(), getNumAtoms() - 1);
|
||||
URANGE_CHECK(bond_pin->getEndAtomIdx(), getNumAtoms() - 1);
|
||||
URANGE_CHECK(bond_pin->getBeginAtomIdx(), getNumAtoms());
|
||||
URANGE_CHECK(bond_pin->getEndAtomIdx(), getNumAtoms());
|
||||
PRECONDITION(bond_pin->getBeginAtomIdx() != bond_pin->getEndAtomIdx(),
|
||||
"attempt to add self-bond");
|
||||
PRECONDITION(!(boost::edge(bond_pin->getBeginAtomIdx(),
|
||||
|
||||
@@ -131,7 +131,7 @@ void RWMol::replaceAtom(unsigned int idx, Atom *atom_pin, bool updateLabel,
|
||||
bool preserveProps) {
|
||||
RDUNUSED_PARAM(updateLabel);
|
||||
PRECONDITION(atom_pin, "bad atom passed to replaceAtom");
|
||||
URANGE_CHECK(idx, getNumAtoms() - 1);
|
||||
URANGE_CHECK(idx, getNumAtoms());
|
||||
Atom *atom_p = atom_pin->copy();
|
||||
atom_p->setOwningMol(this);
|
||||
atom_p->setIdx(idx);
|
||||
@@ -146,7 +146,7 @@ void RWMol::replaceAtom(unsigned int idx, Atom *atom_pin, bool updateLabel,
|
||||
|
||||
void RWMol::replaceBond(unsigned int idx, Bond *bond_pin, bool preserveProps) {
|
||||
PRECONDITION(bond_pin, "bad bond passed to replaceBond");
|
||||
URANGE_CHECK(idx, getNumBonds() - 1);
|
||||
URANGE_CHECK(idx, getNumBonds());
|
||||
BOND_ITER_PAIR bIter = getEdges();
|
||||
for (unsigned int i = 0; i < idx; i++) ++bIter.first;
|
||||
BOND_SPTR obond = d_graph[*(bIter.first)];
|
||||
@@ -271,8 +271,8 @@ void RWMol::removeAtom(Atom *atom) {
|
||||
|
||||
unsigned int RWMol::addBond(unsigned int atomIdx1, unsigned int atomIdx2,
|
||||
Bond::BondType bondType) {
|
||||
URANGE_CHECK(atomIdx1, getNumAtoms() - 1);
|
||||
URANGE_CHECK(atomIdx2, getNumAtoms() - 1);
|
||||
URANGE_CHECK(atomIdx1, getNumAtoms());
|
||||
URANGE_CHECK(atomIdx2, getNumAtoms());
|
||||
PRECONDITION(atomIdx1 != atomIdx2, "attempt to add self-bond");
|
||||
PRECONDITION(!(boost::edge(atomIdx1, atomIdx2, d_graph).second),
|
||||
"bond already exists");
|
||||
@@ -322,8 +322,8 @@ unsigned int RWMol::addBond(Atom::ATOM_SPTR atom1, Atom::ATOM_SPTR atom2,
|
||||
}
|
||||
|
||||
void RWMol::removeBond(unsigned int aid1, unsigned int aid2) {
|
||||
URANGE_CHECK(aid1, getNumAtoms() - 1);
|
||||
URANGE_CHECK(aid2, getNumAtoms() - 1);
|
||||
URANGE_CHECK(aid1, getNumAtoms());
|
||||
URANGE_CHECK(aid2, getNumAtoms());
|
||||
Bond *bnd = getBondBetweenAtoms(aid1, aid2);
|
||||
if (!bnd) return;
|
||||
unsigned int idx = bnd->getIdx();
|
||||
@@ -388,7 +388,7 @@ void RWMol::removeBond(unsigned int aid1, unsigned int aid2) {
|
||||
}
|
||||
|
||||
Bond *RWMol::createPartialBond(unsigned int atomIdx1, Bond::BondType bondType) {
|
||||
URANGE_CHECK(atomIdx1, getNumAtoms() - 1);
|
||||
URANGE_CHECK(atomIdx1, getNumAtoms());
|
||||
|
||||
Bond *b = new Bond(bondType);
|
||||
b->setOwningMol(this);
|
||||
@@ -399,7 +399,7 @@ Bond *RWMol::createPartialBond(unsigned int atomIdx1, Bond::BondType bondType) {
|
||||
unsigned int RWMol::finishPartialBond(unsigned int atomIdx2, int bondBookmark,
|
||||
Bond::BondType bondType) {
|
||||
PRECONDITION(hasBondBookmark(bondBookmark), "no such partial bond");
|
||||
URANGE_CHECK(atomIdx2, getNumAtoms() - 1);
|
||||
URANGE_CHECK(atomIdx2, getNumAtoms());
|
||||
|
||||
Bond *bsp = getBondWithBookmark(bondBookmark);
|
||||
if (bondType == Bond::UNSPECIFIED) {
|
||||
|
||||
@@ -24,7 +24,7 @@ RDGeom::Point2D Snapshot::getPoint2D(unsigned int pointNum) const {
|
||||
PRECONDITION(d_trajectory, "d_trajectory must not be NULL");
|
||||
PRECONDITION(d_trajectory->dimension() == 2, "d_dimension must be == 2");
|
||||
PRECONDITION(d_trajectory->numPoints(), "d_numPoints must be > 0");
|
||||
URANGE_CHECK(pointNum, d_trajectory->numPoints() - 1);
|
||||
URANGE_CHECK(pointNum, d_trajectory->numPoints());
|
||||
unsigned int i = pointNum * d_trajectory->dimension();
|
||||
return RDGeom::Point2D(d_pos[i], d_pos[i + 1]);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ RDGeom::Point3D Snapshot::getPoint3D(unsigned int pointNum) const {
|
||||
PRECONDITION(d_trajectory, "d_trajectory must not be NULL");
|
||||
PRECONDITION(d_trajectory->dimension() >= 2, "d_dimension must be >= 2");
|
||||
PRECONDITION(d_trajectory->numPoints(), "d_numPoints must be > 0");
|
||||
URANGE_CHECK(pointNum, d_trajectory->numPoints() - 1);
|
||||
URANGE_CHECK(pointNum, d_trajectory->numPoints());
|
||||
unsigned int i = pointNum * d_trajectory->dimension();
|
||||
return (RDGeom::Point3D(d_pos[i], d_pos[i + 1],
|
||||
(d_trajectory->dimension() == 3) ? d_pos[i + 2] : 0.0));
|
||||
@@ -65,19 +65,19 @@ unsigned int Trajectory::addSnapshot(const Snapshot &s) {
|
||||
}
|
||||
|
||||
const Snapshot &Trajectory::getSnapshot(unsigned int snapshotNum) const {
|
||||
URANGE_CHECK(snapshotNum + 1, d_snapshotVect->size());
|
||||
URANGE_CHECK(snapshotNum, d_snapshotVect->size());
|
||||
return (*d_snapshotVect)[snapshotNum];
|
||||
}
|
||||
|
||||
unsigned int Trajectory::insertSnapshot(unsigned int snapshotNum, Snapshot s) {
|
||||
URANGE_CHECK(snapshotNum, d_snapshotVect->size());
|
||||
URANGE_CHECK(snapshotNum, d_snapshotVect->size()+1);
|
||||
s.d_trajectory = this;
|
||||
return (d_snapshotVect->insert(d_snapshotVect->begin() + snapshotNum,
|
||||
s) - d_snapshotVect->begin());
|
||||
}
|
||||
|
||||
unsigned int Trajectory::removeSnapshot(unsigned int snapshotNum) {
|
||||
URANGE_CHECK(snapshotNum + 1, d_snapshotVect->size());
|
||||
URANGE_CHECK(snapshotNum, d_snapshotVect->size());
|
||||
return (d_snapshotVect->erase(d_snapshotVect->begin() + snapshotNum) - d_snapshotVect->begin());
|
||||
}
|
||||
|
||||
|
||||
@@ -3996,7 +3996,7 @@ CAS<~>
|
||||
if platform.system() == 'Windows':
|
||||
details = details.replace('\\', '/')
|
||||
self.assertTrue("Code/GraphMol/ROMol.cpp" in details)
|
||||
self.assertTrue("Failed Expression: 3 <= 0" in details)
|
||||
self.assertTrue("Failed Expression: 3 < 1" in details)
|
||||
self.assertTrue("RDKIT:" in details)
|
||||
self.assertTrue(__version__ in details)
|
||||
|
||||
@@ -4360,6 +4360,15 @@ M END
|
||||
"CN[C@@H](C)C(=O)N[C@H](C(=O)N1C[C@@H](Oc2ccccc2)C[C@H]1C(=O)N[C@@H]1CCCc2ccccc21)C1CCCCC1"),
|
||||
True))
|
||||
|
||||
def testGithub1461(self):
|
||||
# this is simple, it should throw a precondition and not seg fault
|
||||
m = Chem.RWMol()
|
||||
try:
|
||||
m.AddBond(0,1,Chem.BondType.SINGLE)
|
||||
self.assertFalse(True) # shouldn't get here
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
if "RDTESTCASE" in os.environ:
|
||||
suite = unittest.TestSuite()
|
||||
|
||||
@@ -42,7 +42,7 @@ void InfoBitRanker::setBiasList(RDKit::INT_VECT &classList) {
|
||||
|
||||
// finally make sure all the class ID in d_biasList are within range
|
||||
for (bi = d_biasList.begin(); bi != d_biasList.end(); bi++) {
|
||||
URANGE_CHECK(static_cast<unsigned int>(*bi), d_classes - 1);
|
||||
URANGE_CHECK(static_cast<unsigned int>(*bi), d_classes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ double InfoBitRanker::BiasInfoEntropyGain(RDKit::USHORT *resMat) const {
|
||||
|
||||
void InfoBitRanker::accumulateVotes(const ExplicitBitVect &bv,
|
||||
unsigned int label) {
|
||||
URANGE_CHECK(label, d_classes - 1);
|
||||
URANGE_CHECK(label, d_classes);
|
||||
CHECK_INVARIANT(bv.getNumBits() == d_dims, "Incorrect bit vector size");
|
||||
|
||||
d_nInst += 1;
|
||||
@@ -129,7 +129,7 @@ void InfoBitRanker::accumulateVotes(const ExplicitBitVect &bv,
|
||||
|
||||
void InfoBitRanker::accumulateVotes(const SparseBitVect &bv,
|
||||
unsigned int label) {
|
||||
URANGE_CHECK(label, d_classes - 1);
|
||||
URANGE_CHECK(label, d_classes);
|
||||
CHECK_INVARIANT(bv.getNumBits() == d_dims, "Incorrect bit vector size");
|
||||
|
||||
d_nInst += 1;
|
||||
|
||||
@@ -80,8 +80,8 @@ class SymmMatrix {
|
||||
}
|
||||
|
||||
TYPE getVal(unsigned int i, unsigned int j) const {
|
||||
URANGE_CHECK(i, d_size - 1);
|
||||
URANGE_CHECK(j, d_size - 1);
|
||||
URANGE_CHECK(i, d_size);
|
||||
URANGE_CHECK(j, d_size);
|
||||
unsigned int id;
|
||||
if (i >= j) {
|
||||
id = i * (i + 1) / 2 + j;
|
||||
@@ -92,8 +92,8 @@ class SymmMatrix {
|
||||
}
|
||||
|
||||
void setVal(unsigned int i, unsigned int j, TYPE val) {
|
||||
URANGE_CHECK(i, d_size - 1);
|
||||
URANGE_CHECK(j, d_size - 1);
|
||||
URANGE_CHECK(i, d_size);
|
||||
URANGE_CHECK(j, d_size);
|
||||
unsigned int id;
|
||||
if (i >= j) {
|
||||
id = i * (i + 1) / 2 + j;
|
||||
|
||||
@@ -138,9 +138,9 @@ std::ostream& operator<<(std::ostream& s, const Invariant& inv);
|
||||
}
|
||||
|
||||
#define URANGE_CHECK(x, hi) \
|
||||
if ((x) > (hi)) { \
|
||||
if (x >= (hi)) { \
|
||||
std::stringstream errstr; \
|
||||
errstr << x << " <= " << hi; \
|
||||
errstr << x << " < " << hi; \
|
||||
Invar::Invariant inv("Range Error", #x, errstr.str().c_str(), __FILE__, \
|
||||
__LINE__); \
|
||||
BOOST_LOG(rdErrorLog) << "\n\n****\n" << inv << "****\n\n"; \
|
||||
@@ -163,7 +163,7 @@ std::ostream& operator<<(std::ostream& s, const Invariant& inv);
|
||||
#define UNDER_CONSTRUCTION(fn) assert(0);
|
||||
#define RANGE_CHECK(lo, x, hi) \
|
||||
assert((lo) <= (hi) && (x) >= (lo) && (x) <= (hi));
|
||||
#define URANGE_CHECK(lo, x, hi) assert((x) <= (hi));
|
||||
#define URANGE_CHECK(lo, x, hi) assert((hi>0) && (x < hi));
|
||||
#define TEST_ASSERT(expr) assert(expr);
|
||||
|
||||
#elif INVARIANT_SILENT_METHOD
|
||||
|
||||
Reference in New Issue
Block a user