MolPickler.h
Go to the documentation of this file.
//
// Copyright (C) 2001-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.
//
#ifndef _RD_MOLPICKLE_H
#define _RD_MOLPICKLE_H
#include <Geometry/point.h>
#include <GraphMol/Atom.h>
#include <GraphMol/QueryAtom.h>
#include <GraphMol/Bond.h>
#include <GraphMol/QueryBond.h>
// Std stuff
#include <iostream>
#include <string>
#include <sstream>
#include <exception>
#ifdef WIN32
#include <ios>
#endif
#include <boost/cstdint.hpp>
namespace RDKit{
class ROMol;
class RingInfo;
//! used to indicate exceptions whilst pickling (serializing) molecules
class MolPicklerException : public std::exception {
public :
MolPicklerException(const char *msg) : _msg(msg) {};
MolPicklerException(const std::string msg) : _msg(msg) {};
const char *message () const { return _msg.c_str(); };
~MolPicklerException () throw () {};
private :
std::string _msg;
};
//! handles pickling (serializing) molecules
class MolPickler{
public:
static const boost::int32_t versionMajor,versionMinor,versionPatch; //!< mark the pickle version
static const boost::int32_t endianId; //! mark the endian-ness of the pickle
//! the pickle format is tagged using these tags:
//! NOTE: if you add to this list, be sure to put new entries AT THE BOTTOM, otherwise
//! you will break old pickles.
typedef enum {
VERSION=0,
BEGINATOM,
ATOM_INDEX,
ATOM_NUMBER,
ATOM_POS,
ATOM_CHARGE,
ATOM_NEXPLICIT,
ATOM_CHIRALTAG,
ATOM_MASS,
ATOM_ISAROMATIC,
ENDATOM,
BEGINBOND,
BOND_INDEX,
BOND_BEGATOMIDX,
BOND_ENDATOMIDX,
BOND_TYPE,
BOND_DIR,
ENDBOND,
BEGINPROPS,
ENDPROPS,
BEGINSSSR,
ENDSSSR,
ENDMOL,
BEGINCONFS,
ATOM_MAPNUMBER,
BEGINQUERY,
QUERY_VALUE,
QUERY_ISNEGATED,
QUERY_NUMCHILDREN,
QUERY_BOOL,
QUERY_AND,
QUERY_OR,
QUERY_XOR,
QUERY_EQUALS,
QUERY_GREATER,
QUERY_GREATEREQUAL,
QUERY_LESS,
QUERY_LESSEQUAL,
QUERY_RANGE,
QUERY_SET,
QUERY_NULL,
QUERY_ATOMRING,
QUERY_RECURSIVE,
ENDQUERY,
ATOM_DUMMYLABEL,
BEGIN_ATOM_MONOMER,
ATOM_PDB_RESIDUE_SERIALNUMBER,
ATOM_PDB_RESIDUE_ALTLOC,
ATOM_PDB_RESIDUE_RESIDUENAME,
ATOM_PDB_RESIDUE_CHAINID,
ATOM_PDB_RESIDUE_INSERTIONCODE,
ATOM_PDB_RESIDUE_OCCUPANCY,
ATOM_PDB_RESIDUE_TEMPFACTOR,
ATOM_PDB_RESIDUE_ISHETEROATOM,
ATOM_PDB_RESIDUE_SECONDARYSTRUCTURE,
ATOM_PDB_RESIDUE_RESIDUENUMBER,
ATOM_PDB_RESIDUE_SEGMENTNUMBER,
END_ATOM_MONOMER,
} Tags;
//! pickles a molecule and sends the results to stream \c ss
static void pickleMol(const ROMol *mol,std::ostream &ss);
static void pickleMol(const ROMol &mol,std::ostream &ss) {MolPickler::pickleMol(&mol,ss);};
//! pickles a molecule and adds the results to string \c res
static void pickleMol(const ROMol *mol,std::string &res);
static void pickleMol(const ROMol &mol,std::string &res) {MolPickler::pickleMol(&mol,res);};
//! constructs a molecule from a pickle stored in a string
static void molFromPickle(const std::string &pickle,ROMol *mol);
static void molFromPickle(const std::string &pickle,ROMol &mol) {MolPickler::molFromPickle(pickle,&mol);};
//! constructs a molecule from a pickle stored in a stream
static void molFromPickle(std::istream &ss,ROMol *mol);
static void molFromPickle(std::istream &ss,ROMol &mol) { MolPickler::molFromPickle(ss,&mol); };
private:
//! do the actual work of pickling a molecule
template <typename T>
static void _pickle(const ROMol *mol,std::ostream &ss);
//! do the actual work of pickling an Atom
template <typename T>
static void _pickleAtom(std::ostream &ss,const Atom *atom);
//! do the actual work of pickling a Bond
template <typename T>
static void _pickleBond(std::ostream &ss,const Bond *bond,
std::map<int,int> &atomIdxMap);
//! do the actual work of pickling an SSSR structure
template <typename T>
static void _pickleSSSR(std::ostream &ss,const RingInfo *ringInfo,
std::map<int,int> &atomIdxMap);
//! do the actual work of pickling a Conformer
template <typename T>
static void _pickleConformer(std::ostream &ss,const Conformer *conf);
//! do the actual work of de-pickling a molecule
template <typename T>
static void _depickle(std::istream &ss,ROMol *mol, int version,int numAtoms);
//! extract atomic data from a pickle and add the resulting Atom to the molecule
template <typename T>
static Atom *_addAtomFromPickle(std::istream &ss,ROMol *mol, RDGeom::Point3D &pos,
int version,
bool directMap=false);
//! extract bond data from a pickle and add the resulting Bond to the molecule
template <typename T>
static Bond *_addBondFromPickle(std::istream &ss,ROMol *mol,
int version,
bool directMap=false);
//! extract ring info from a pickle and add the resulting RingInfo to the molecule
template <typename T>
static void _addRingInfoFromPickle(std::istream &ss,ROMol *mol,
int version,
bool directMap=false);
//! extract a conformation from a pickle
template <typename T>
static Conformer *_conformerFromPickle(std::istream &ss,int version);
//! backwards compatibility
static void _pickleV1(const ROMol *mol,std::ostream &ss);
//! backwards compatibility
static void _depickleV1(std::istream &ss,ROMol *mol);
//! backwards compatibility
static void _addAtomFromPickleV1(std::istream &ss,ROMol *mol);
//! backwards compatibility
static void _addBondFromPickleV1(std::istream &ss,ROMol *mol);
};
};
#endif
RDKit::MolPickler::END_ATOM_MONOMER
Definition: MolPickler.h:112
RDKit::MolPickler::ENDQUERY
Definition: MolPickler.h:98
RDKit::MolPickler::QUERY_AND
Definition: MolPickler.h:85
RDKit::MolPickler::BEGINATOM
Definition: MolPickler.h:56
RDKit::MolPickler::ATOM_INDEX
Definition: MolPickler.h:57
RDKit::MolPickler::QUERY_XOR
Definition: MolPickler.h:87
RDKit::MolPickler::ATOM_PDB_RESIDUE_TEMPFACTOR
Definition: MolPickler.h:107
RDKit::MolPickler::pickleMol
static void pickleMol(const ROMol *mol, std::ostream &ss)
pickles a molecule and sends the results to stream ss
RDKit::MolPickler::ATOM_PDB_RESIDUE_INSERTIONCODE
Definition: MolPickler.h:105
RDKit::MolPicklerException::MolPicklerException
MolPicklerException(const char *msg)
Definition: MolPickler.h:36
RDKit::MolPickler::ATOM_CHARGE
Definition: MolPickler.h:60
RDKit::MolPickler::ATOM_PDB_RESIDUE_SERIALNUMBER
Definition: MolPickler.h:101
RDKit::MolPickler::ATOM_MASS
Definition: MolPickler.h:63
QueryBond.h
RDKit::MolPickler::BOND_DIR
Definition: MolPickler.h:71
RDKit::MolPickler::BEGINSSSR
Definition: MolPickler.h:75
RDKit::MolPickler::pickleMol
static void pickleMol(const ROMol &mol, std::string &res)
Definition: MolPickler.h:120
RDKit::MolPickler::QUERY_GREATEREQUAL
Definition: MolPickler.h:90
point.h
RDKit::MolPickler::ENDPROPS
Definition: MolPickler.h:74
RDKit::MolPickler::Tags
Tags
mark the endian-ness of the pickle
Definition: MolPickler.h:54
RDKit::MolPickler::versionMajor
static const boost::int32_t versionMajor
Definition: MolPickler.h:48
RDKit::MolPickler::ATOM_NEXPLICIT
Definition: MolPickler.h:61
RDKit::MolPickler::BEGINBOND
Definition: MolPickler.h:66
RDKit::MolPickler::versionMinor
static const boost::int32_t versionMinor
Definition: MolPickler.h:48
RDKit::MolPickler::QUERY_RANGE
Definition: MolPickler.h:93
RDKit::MolPickler::ENDATOM
Definition: MolPickler.h:65
RDKit::MolPickler::QUERY_RECURSIVE
Definition: MolPickler.h:97
RDKit::MolPickler::versionPatch
static const boost::int32_t versionPatch
mark the pickle version
Definition: MolPickler.h:48
RDKit::MolPickler::BOND_TYPE
Definition: MolPickler.h:70
RDKit::MolPickler::ENDSSSR
Definition: MolPickler.h:76
RDKit::ROMol
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:105
RDKit::MolPickler::ATOM_PDB_RESIDUE_RESIDUENUMBER
Definition: MolPickler.h:110
RDKit::MolPickler::QUERY_LESSEQUAL
Definition: MolPickler.h:92
RDKit::MolPickler::QUERY_LESS
Definition: MolPickler.h:91
RDKit::MolPickler::BEGIN_ATOM_MONOMER
Definition: MolPickler.h:100
RDKit::MolPickler::BOND_BEGATOMIDX
Definition: MolPickler.h:68
RDKit::MolPickler::molFromPickle
static void molFromPickle(const std::string &pickle, ROMol &mol)
Definition: MolPickler.h:124
RDKit::MolPickler::QUERY_VALUE
Definition: MolPickler.h:81
RDKit::MolPickler::QUERY_ISNEGATED
Definition: MolPickler.h:82
RDKit::MolPickler::QUERY_EQUALS
Definition: MolPickler.h:88
RDKit::MolPickler::ATOM_MAPNUMBER
Definition: MolPickler.h:79
RDKit::MolPickler::endianId
static const boost::int32_t endianId
Definition: MolPickler.h:49
RDKit::MolPickler::BEGINCONFS
Definition: MolPickler.h:78
Bond.h
RDKit::MolPickler::ATOM_DUMMYLABEL
Definition: MolPickler.h:99
RDKit::MolPickler::ATOM_PDB_RESIDUE_ALTLOC
Definition: MolPickler.h:102
RDKit::MolPickler::ATOM_PDB_RESIDUE_RESIDUENAME
Definition: MolPickler.h:103
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::MolPickler::QUERY_NUMCHILDREN
Definition: MolPickler.h:83
RDKit::RingInfo
A class to store information about a molecule's rings.
Definition: RingInfo.h:21
RDKit::MolPicklerException
used to indicate exceptions whilst pickling (serializing) molecules
Definition: MolPickler.h:34
RDKit::MolPickler::VERSION
Definition: MolPickler.h:55
RDKit::MolPickler::ATOM_NUMBER
Definition: MolPickler.h:58
RDKit::MolPickler::ATOM_ISAROMATIC
Definition: MolPickler.h:64
RDKit::MolPickler::QUERY_GREATER
Definition: MolPickler.h:89
RDKit::MolPickler::BOND_ENDATOMIDX
Definition: MolPickler.h:69
RDKit::Bond
class for representing a bond
Definition: Bond.h:46
RDKit::MolPicklerException::MolPicklerException
MolPicklerException(const std::string msg)
Definition: MolPickler.h:37
RDGeom::Point3D
Definition: point.h:48
RDKit::MolPickler::QUERY_OR
Definition: MolPickler.h:86
RDKit::MolPickler::ATOM_PDB_RESIDUE_OCCUPANCY
Definition: MolPickler.h:106
RDKit::MolPickler::BEGINQUERY
Definition: MolPickler.h:80
RDKit::MolPickler
handles pickling (serializing) molecules
Definition: MolPickler.h:46
RDKit::MolPickler::BEGINPROPS
Definition: MolPickler.h:73
RDKit::Conformer
The class for representing 2D or 3D conformation of a molecule.
Definition: Conformer.h:41
RDKit::MolPickler::molFromPickle
static void molFromPickle(const std::string &pickle, ROMol *mol)
constructs a molecule from a pickle stored in a string
RDKit::MolPicklerException::message
const char * message() const
Definition: MolPickler.h:38
RDKit::MolPickler::BOND_INDEX
Definition: MolPickler.h:67
RDKit::MolPickler::ATOM_PDB_RESIDUE_SEGMENTNUMBER
Definition: MolPickler.h:111
RDKit::MolPickler::molFromPickle
static void molFromPickle(std::istream &ss, ROMol &mol)
Definition: MolPickler.h:128
RDKit::MolPickler::ENDMOL
Definition: MolPickler.h:77
RDKit::MolPickler::ATOM_PDB_RESIDUE_ISHETEROATOM
Definition: MolPickler.h:108
RDKit::MolPickler::ATOM_PDB_RESIDUE_CHAINID
Definition: MolPickler.h:104
Atom.h
Defines the Atom class and associated typedefs.
RDKit::MolPickler::ATOM_CHIRALTAG
Definition: MolPickler.h:62
RDKit::MolPickler::QUERY_ATOMRING
Definition: MolPickler.h:96
RDKit::MolPickler::pickleMol
static void pickleMol(const ROMol &mol, std::ostream &ss)
Definition: MolPickler.h:117
RDKit::MolPickler::ATOM_PDB_RESIDUE_SECONDARYSTRUCTURE
Definition: MolPickler.h:109
RDKit::MolPickler::ENDBOND
Definition: MolPickler.h:72
QueryAtom.h
RDKit::MolPickler::QUERY_BOOL
Definition: MolPickler.h:84
RDKit::MolPickler::QUERY_NULL
Definition: MolPickler.h:95
RDKit::MolPickler::QUERY_SET
Definition: MolPickler.h:94
RDKit::MolPickler::ATOM_POS
Definition: MolPickler.h:59
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:67
RDKit::MolPicklerException::~MolPicklerException
~MolPicklerException()
Definition: MolPickler.h:39