RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
RegisterDescriptor.h
Go to the documentation of this file.
1//
2// Copyright (c) 2016, Novartis Institutes for BioMedical Research Inc.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following
13// disclaimer in the documentation and/or other materials provided
14// with the distribution.
15// * Neither the name of Novartis Institutes for BioMedical Research Inc.
16// nor the names of its contributors may be used to endorse or promote
17// products derived from this software without specific prior written
18// permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//
32
33#include <RDGeneral/export.h>
34#ifndef RDKIT_REGISTER_DESCRIPTOR_H
35#define RDKIT_REGISTER_DESCRIPTOR_H
36
38#include <boost/shared_ptr.hpp>
40#include "Property.h"
41
42namespace RDKit {
43class ROMol;
44namespace Descriptors {
45
46// these macros create a static class that can call the specified function.
47// using double class::operator(const ROMol&)
48// this class also contains a function pointer with the signature
49// double(*)(const ROMol&)
50// these classes are automatically registered with the property registry
51/*
52#define REGISTER_FULL_DESCRIPTOR( NAME, VERSION, FUNC ) \
53double NAME##PropertyFunction(const ROMol&m){return
54static_cast<double>(FUNC(mol));}\
55struct NAME##PropertyFunctor : public PropertyFunctor{ \
56 NAME##PropertyFunctor(bool registerProp=true) : PropertyFunctor(#NAME,
57VERSION) { \
58 if (registerProp) Properties::registerProperty(new
59NAME##PropertyFunctor(false)); \
60 d_dataFunc = &NAME##PropertyFunction; \
61 } \
62 double operator()(const RDKit::ROMol &mol) const { \
63 return NAME##PropertyFunction(mol); } \
64}; \
65static NAME##PropertyFunctor NAME##PropertyFunctor__;
66*/
67
68#define REGISTER_DESCRIPTOR(NAME, FUNC) \
69 struct NAME##PropertyFunctor : public PropertyFunctor { \
70 static double _func(const ROMol &m) { \
71 return static_cast<double>(FUNC(m)); \
72 } \
73 NAME##PropertyFunctor(bool registerProp = true) \
74 : PropertyFunctor(#NAME, NAME##Version, _func) { \
75 if (registerProp) \
76 Properties::registerProperty(new NAME##PropertyFunctor(false)); \
77 } \
78 double operator()(const RDKit::ROMol &mol) const { return _func(mol); } \
79 }; \
80 static NAME##PropertyFunctor NAME##PropertyFunctor__;
81} // namespace Descriptors
82} // namespace RDKit
83
84#endif
Std stuff.