1 /**********************************************************************
2 AddNonPolarH.cpp - The option --AddNonPolarH  adds hydrogen to polar atoms only.
3 
4 Copyright(C) 2007 by Chris Morley
5 
6 This file is part of the Open Babel project.
7 For more information, see <http://openbabel.org/>
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 ***********************************************************************/
18 #include <openbabel/babelconfig.h>
19 #include <iostream>
20 #include<openbabel/op.h>
21 #include<openbabel/mol.h>
22 
23 namespace OpenBabel
24 {
25 
26 class OpAddNonPolarH : public OBOp
27 {
28 public:
OpAddNonPolarH(const char * ID)29   OpAddNonPolarH(const char* ID) : OBOp(ID, false){};
Description()30   const char* Description(){ return "Adds hydrogen to nonpolar atoms only"; }
31 
WorksWith(OBBase * pOb) const32   virtual bool WorksWith(OBBase* pOb) const { return dynamic_cast<OBMol*>(pOb) != nullptr; }
33   virtual bool Do(OBBase* pOb, const char* OptionText=nullptr, OpMap* pOptions=nullptr, OBConversion* pConv=nullptr);
34 };
35 
36 /////////////////////////////////////////////////////////////////
37 OpAddNonPolarH theOpAddNonPolarH("AddNonPolarH"); //Global instance
38 
39 /////////////////////////////////////////////////////////////////
Do(OBBase * pOb,const char * OptionText,OpMap * pOptions,OBConversion * pConv)40 bool OpAddNonPolarH::Do(OBBase* pOb, const char* OptionText, OpMap* pOptions, OBConversion* pConv)
41 {
42   OBMol* pmol = dynamic_cast<OBMol*>(pOb);
43   if(!pmol)
44     return false;
45 
46   pmol->AddNonPolarHydrogens();
47 
48   return true;
49 }
50 }//namespace
51