diff --git a/Code/GraphMol/CMakeLists.txt b/Code/GraphMol/CMakeLists.txt index 3c567b66e..0e4b608f3 100644 --- a/Code/GraphMol/CMakeLists.txt +++ b/Code/GraphMol/CMakeLists.txt @@ -7,7 +7,7 @@ rdkit_library(GraphMol MolDiscriminators.cpp ConjugHybrid.cpp AddHs.cpp Matrices.cpp Chirality.cpp RingInfo.cpp Conformer.cpp Renumber.cpp AdjustQuery.cpp Resonance.cpp StereoGroup.cpp - new_canon.cpp SubstanceGroup.cpp FindStereo.cpp + new_canon.cpp SubstanceGroup.cpp FindStereo.cpp MonomerInfo.cpp SHARED LINK_LIBRARIES RDGeometryLib RDGeneral ) target_compile_definitions(GraphMol PRIVATE RDKIT_GRAPHMOL_BUILD) diff --git a/Code/GraphMol/MonomerInfo.cpp b/Code/GraphMol/MonomerInfo.cpp new file mode 100644 index 000000000..817d5b0f6 --- /dev/null +++ b/Code/GraphMol/MonomerInfo.cpp @@ -0,0 +1,21 @@ +// +// Copyright (C) 2021 Greg Landrum 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 +#include "MonomerInfo.h" + +using namespace RDKit; + +//! allows AtomPDBResidueInfo objects to be dumped to streams +std::ostream &operator<<(std::ostream &target, const AtomPDBResidueInfo &apri) { + target << apri.getSerialNumber() << " " << apri.getName() << " " + << apri.getResidueName() << " " << apri.getChainId() << " " + << apri.getResidueNumber(); + return target; +} diff --git a/Code/GraphMol/MonomerInfo.h b/Code/GraphMol/MonomerInfo.h index af9b5dadd..f373448ce 100644 --- a/Code/GraphMol/MonomerInfo.h +++ b/Code/GraphMol/MonomerInfo.h @@ -1,5 +1,5 @@ // -// Copyright (C) 2013 Greg Landrum +// Copyright (C) 2013-2021 Greg Landrum and other RDKit contributors // // @@ All Rights Reserved @@ // This file is part of the RDKit. @@ -13,8 +13,8 @@ */ #include -#ifndef _RD_MONOMERINFO_H -#define _RD_MONOMERINFO_H +#ifndef RD_MONOMERINFO_H +#define RD_MONOMERINFO_H #include #include diff --git a/Code/GraphMol/catch_graphmol.cpp b/Code/GraphMol/catch_graphmol.cpp index e9fe61465..0376bf220 100644 --- a/Code/GraphMol/catch_graphmol.cpp +++ b/Code/GraphMol/catch_graphmol.cpp @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -2434,4 +2436,27 @@ TEST_CASE("KekulizeIfPossible") { } } } +} + +TEST_CASE("Github #4535: operator<< for AtomPDBResidue", "[PDB]") { + SECTION("basics") { + bool sanitize = true; + int flavor = 0; + std::unique_ptr mol(SequenceToMol("KY", sanitize, flavor)); + REQUIRE(mol); + REQUIRE(mol->getAtomWithIdx(0)->getMonomerInfo()); + auto res = static_cast( + mol->getAtomWithIdx(0)->getMonomerInfo()); + REQUIRE(res); + std::stringstream oss; + oss << *res << std::endl; + res = static_cast( + mol->getAtomWithIdx(mol->getNumAtoms() - 1)->getMonomerInfo()); + REQUIRE(res); + oss << *res << std::endl; + auto tgt = R"FOO(1 N LYS A 1 +22 OXT TYR A 2 +)FOO"; + CHECK(oss.str() == tgt); + } } \ No newline at end of file