Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PandasTools work with pandas v2.2 #7224

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 8 additions & 18 deletions Code/GraphMol/Atom.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2001-2021 Greg Landrum and other RDKit contributors
// Copyright (C) 2001-2024 Greg Landrum and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
Expand Down Expand Up @@ -230,11 +230,7 @@ void Atom::initAtom() {
d_explicitValence = -1;
}

Atom::~Atom() {
if (dp_monomerInfo) {
delete dp_monomerInfo;
}
}
Atom::~Atom() { delete dp_monomerInfo; }

Atom *Atom::copy() const {
auto *res = new Atom(*this);
Expand Down Expand Up @@ -317,7 +313,6 @@ unsigned int Atom::getTotalValence() const {
namespace {

int calculateExplicitValence(const Atom &atom, bool strict, bool checkIt) {
unsigned int res;
// FIX: contributions of bonds to valence are being done at best
// approximately
double accum = 0;
Expand Down Expand Up @@ -349,8 +344,7 @@ int calculateExplicitValence(const Atom &atom, bool strict, bool checkIt) {
// nitrogen here : c1cccn1C

int pval = dv + chr;
const INT_VECT &valens =
PeriodicTable::getTable()->getValenceList(atomicNum);
const auto &valens = PeriodicTable::getTable()->getValenceList(atomicNum);
for (auto val : valens) {
if (val == -1) {
break;
Expand Down Expand Up @@ -386,7 +380,7 @@ int calculateExplicitValence(const Atom &atom, bool strict, bool checkIt) {
// correctly.
accum += 0.1;

res = static_cast<int>(std::round(accum));
auto res = static_cast<int>(std::round(accum));

if (strict || checkIt) {
int effectiveValence;
Expand All @@ -397,8 +391,7 @@ int calculateExplicitValence(const Atom &atom, bool strict, bool checkIt) {
// extra valences means adding negative charge
effectiveValence = res + atom.getFormalCharge();
}
const INT_VECT &valens =
PeriodicTable::getTable()->getValenceList(atomicNum);
const auto &valens = PeriodicTable::getTable()->getValenceList(atomicNum);

int maxValence = valens.back();
// maxValence == -1 signifies that we'll take anything at the high end
Expand Down Expand Up @@ -437,9 +430,7 @@ int calculateImplicitValence(const Atom &atom, bool strict, bool checkIt) {
if (atomic_num == 0) {
return 0;
}
for (const auto &nbri :
boost::make_iterator_range(atom.getOwningMol().getAtomBonds(&atom))) {
const auto bnd = atom.getOwningMol()[nbri];
for (const auto bnd : atom.getOwningMol().atomBonds(&atom)) {
if (QueryOps::hasComplexBondTypeQuery(*bnd)) {
return 0;
}
Expand Down Expand Up @@ -471,7 +462,6 @@ int calculateImplicitValence(const Atom &atom, bool strict, bool checkIt) {
// the atom and the explicit valence already specified - tells how
// many Hs to add
//
int res;

// The d-block and f-block of the periodic table (i.e. transition metals,
// lanthanoids and actinoids) have no default valence.
Expand All @@ -491,8 +481,7 @@ int calculateImplicitValence(const Atom &atom, bool strict, bool checkIt) {
// exception
// finally aromatic cases are dealt with differently - these atoms are allowed
// only default valences
const INT_VECT &valens =
PeriodicTable::getTable()->getValenceList(atomic_num);
const auto &valens = PeriodicTable::getTable()->getValenceList(atomic_num);

int explicitPlusRadV =
atom.getExplicitValence() + atom.getNumRadicalElectrons();
Expand Down Expand Up @@ -535,6 +524,7 @@ int calculateImplicitValence(const Atom &atom, bool strict, bool checkIt) {
chg = -chg;
}

int res = 0;
// if we have an aromatic case treat it differently
if (isAromaticAtom(atom)) {
if (explicitPlusRadV <= (static_cast<int>(dv) + chg)) {
Expand Down
2 changes: 1 addition & 1 deletion Code/GraphMol/Bond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void Bond::setStereoAtoms(unsigned int bgnIdx, unsigned int endIdx) {
getOwningMol().getBondBetweenAtoms(getEndAtomIdx(), endIdx) != nullptr,
"endIdx not connected to end atom of bond");

INT_VECT &atoms = getStereoAtoms();
auto &atoms = getStereoAtoms();
atoms.clear();
atoms.push_back(bgnIdx);
atoms.push_back(endIdx);
Expand Down
32 changes: 4 additions & 28 deletions Code/GraphMol/Conformer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// $Id$
//
// Copyright (C) 2001-2008 Greg Landrum and Rational Discovery LLC
// Copyright (C) 2001-2024 Greg Landrum and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
Expand All @@ -13,27 +12,6 @@

namespace RDKit {

void Conformer::initFromOther(const Conformer &conf) {
RDProps::operator=(conf);
dp_mol = conf.dp_mol;
auto nat = conf.getNumAtoms();
d_positions.resize(nat);
for (unsigned i = 0; i < nat; i++) {
d_positions[i] = conf.getAtomPos(i);
}
d_id = conf.getId();
df_is3D = conf.is3D();
}

Conformer::Conformer(const Conformer &conf) : RDProps() { initFromOther(conf); }
Conformer &Conformer::operator=(const Conformer &other) {
if (this == &other) {
return *this;
}
initFromOther(other);
return *this;
}

void Conformer::setOwningMol(ROMol *mol) {
PRECONDITION(mol, "");
dp_mol = mol;
Expand All @@ -48,23 +26,21 @@ const RDGeom::POINT3D_VECT &Conformer::getPositions() const {
return d_positions;
}

RDGeom::POINT3D_VECT &Conformer::getPositions() {
return d_positions;
}
RDGeom::POINT3D_VECT &Conformer::getPositions() { return d_positions; }

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());
return d_positions[atomId];
return d_positions.at(atomId);
}

RDGeom::Point3D &Conformer::getAtomPos(unsigned int atomId) {
if (dp_mol) {
PRECONDITION(dp_mol->getNumAtoms() == d_positions.size(), "");
}
URANGE_CHECK(atomId, d_positions.size());
return d_positions[atomId];
return d_positions.at(atomId);
}
} // namespace RDKit
35 changes: 14 additions & 21 deletions Code/GraphMol/Conformer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2001-2021 Greg Landrum and other RDKit contributors
// Copyright (C) 2001-2024 Greg Landrum and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
Expand Down Expand Up @@ -48,35 +48,29 @@ class RDKIT_GRAPHMOL_EXPORT Conformer : public RDProps {
friend class ROMol;

//! Constructor
Conformer() { d_positions.clear(); }
Conformer() = default;

//! Constructor with number of atoms specified ID specification
Conformer(unsigned int numAtoms) {
if (numAtoms) {
d_positions.resize(numAtoms, RDGeom::Point3D(0.0, 0.0, 0.0));
} else {
d_positions.resize(0);
d_positions.clear();
}
}
Conformer(unsigned int numAtoms)
: d_positions(numAtoms, RDGeom::Point3D(0.0, 0.0, 0.0)) {}

//! Copy Constructor: initialize from a second conformation.
Conformer(const Conformer &other);
Conformer &operator=(const Conformer &other);
Conformer(const Conformer &other) = default;
Conformer &operator=(const Conformer &other) = default;
Conformer(Conformer &&o) noexcept
: RDProps(std::move(o)),
df_is3D(std::move(o.df_is3D)),
d_id(std::move(o.d_id)),
dp_mol(std::move(o.dp_mol)),
d_positions(std::move(o.d_positions)){};
: RDProps(o),
df_is3D(o.df_is3D),
d_id(o.d_id),
dp_mol(o.dp_mol),
d_positions(std::move(o.d_positions)) {}
Conformer &operator=(Conformer &&o) noexcept {
if (this == &o) {
return *this;
}
RDProps::operator=(std::move(o));
df_is3D = std::move(o.df_is3D);
d_id = std::move(o.d_id);
dp_mol = std::move(o.dp_mol);
df_is3D = o.df_is3D;
d_id = d_id;
dp_mol = dp_mol;
d_positions = std::move(o.d_positions);
return *this;
}
Expand Down Expand Up @@ -161,7 +155,6 @@ class RDKIT_GRAPHMOL_EXPORT Conformer : public RDProps {
unsigned int d_id{0}; // id is the conformation
ROMol *dp_mol{nullptr}; // owning molecule
RDGeom::POINT3D_VECT d_positions; // positions of the atoms
void initFromOther(const Conformer &conf);
};

typedef boost::shared_ptr<Conformer> CONFORMER_SPTR;
Expand Down
23 changes: 5 additions & 18 deletions Code/GraphMol/MonomerInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2013-2021 Greg Landrum and other RDKit contributors
// Copyright (C) 2013-2024 Greg Landrum and other RDKit contributors
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
Expand Down Expand Up @@ -29,11 +29,10 @@ class RDKIT_GRAPHMOL_EXPORT AtomMonomerInfo {

virtual ~AtomMonomerInfo() {}

AtomMonomerInfo() : d_name("") {}
AtomMonomerInfo() = default;
AtomMonomerInfo(AtomMonomerType typ, std::string nm = "")
: d_monomerType(typ), d_name(std::move(nm)) {}
AtomMonomerInfo(const AtomMonomerInfo &other)
: d_monomerType(other.d_monomerType), d_name(other.d_name) {}
AtomMonomerInfo(const AtomMonomerInfo &other) = default;

const std::string &getName() const { return d_name; }
void setName(const std::string &nm) { d_name = nm; }
Expand All @@ -44,26 +43,14 @@ class RDKIT_GRAPHMOL_EXPORT AtomMonomerInfo {

private:
AtomMonomerType d_monomerType{UNKNOWN};
std::string d_name;
std::string d_name{""};
};

//! Captures atom-level information about peptide residues
class RDKIT_GRAPHMOL_EXPORT AtomPDBResidueInfo : public AtomMonomerInfo {
public:
AtomPDBResidueInfo() : AtomMonomerInfo(PDBRESIDUE) {}
AtomPDBResidueInfo(const AtomPDBResidueInfo &other)
: AtomMonomerInfo(other),
d_serialNumber(other.d_serialNumber),
d_altLoc(other.d_altLoc),
d_residueName(other.d_residueName),
d_residueNumber(other.d_residueNumber),
d_chainId(other.d_chainId),
d_insertionCode(other.d_insertionCode),
d_occupancy(other.d_occupancy),
d_tempFactor(other.d_tempFactor),
df_heteroAtom(other.df_heteroAtom),
d_secondaryStructure(other.d_secondaryStructure),
d_segmentNumber(other.d_segmentNumber) {}
AtomPDBResidueInfo(const AtomPDBResidueInfo &other) = default;

AtomPDBResidueInfo(const std::string &atomName, int serialNumber = 0,
std::string altLoc = "", std::string residueName = "",
Expand Down
8 changes: 4 additions & 4 deletions Code/GraphMol/QueryAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ class RDKIT_GRAPHMOL_EXPORT QueryAtom : public Atom {
}; // end o' class

namespace detail {
inline std::string qhelper(Atom::QUERYATOM_QUERY *q, unsigned int depth) {
inline std::string qhelper(const Atom::QUERYATOM_QUERY *q, unsigned int depth) {
std::string res = "";
if (q) {
for (unsigned int i = 0; i < depth; ++i) {
res += " ";
}
res += q->getFullDescription() + "\n";
for (Atom::QUERYATOM_QUERY::CHILD_VECT_CI ci = q->beginChildren();
ci != q->endChildren(); ++ci) {
res += qhelper((*ci).get(), depth + 1);
for (const auto &child :
boost::make_iterator_range(q->beginChildren(), q->endChildren())) {
res += qhelper(child.get(), depth + 1);
}
}
return res;
Expand Down
8 changes: 4 additions & 4 deletions Code/GraphMol/QueryBond.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ class RDKIT_GRAPHMOL_EXPORT QueryBond : public Bond {
};

namespace detail {
inline std::string qhelper(Bond::QUERYBOND_QUERY *q, unsigned int depth) {
inline std::string qhelper(const Bond::QUERYBOND_QUERY *q, unsigned int depth) {
std::string res;
if (q) {
for (unsigned int i = 0; i < depth; ++i) {
res += " ";
}
res += q->getFullDescription() + "\n";
for (Bond::QUERYBOND_QUERY::CHILD_VECT_CI ci = q->beginChildren();
ci != q->endChildren(); ++ci) {
res += qhelper((*ci).get(), depth + 1);
for (const auto &child :
boost::make_iterator_range(q->beginChildren(), q->endChildren())) {
res += qhelper(child.get(), depth + 1);
}
}
return res;
Expand Down