Ouch, you are right. This is much better (attached).
Thanks a lot,
Paolo
AddPolarNonPolarHydrogens().
Please don't. Why don't you do something like:
AddNewHydrogens(enum HydrogenType = All, PolarOnly, NonPolarOnly);
The latter accepts two bool arguments, addpolar and addnonpolar:
The problem with bool arguments is that they're unclear. If I forget the order,
I get totally unexpected behavior.
- false, false will do nothing
Case in point, no one would call the method expecting nothing to happen. So
using an enum is a much better option here.
So I'd suggest adding a new method with an enum for both adding/deleting as you
suggest.
Best regards,
-Geoff
--
==========================================================
Paolo Tosco, Ph.D. Phone: +39 011 6707680
Department of Drug Science Fax: +39 011 6707687
and Technology Mob: +39 348 5537206
Via Pietro Giuria, 9
10125 Torino, Italy
http://open3dalign.org
E-mail: paolo.to...@unito.it http://open3dqsar.org
==========================================================
diff -aruN openbabel_svn_4712.orig/src/CMakeLists.txt openbabel_svn_4712/src/CMakeLists.txt
--- openbabel_svn_4712.orig/src/CMakeLists.txt 2012-02-23 13:26:46.867091714 +0100
+++ openbabel_svn_4712/src/CMakeLists.txt 2012-02-23 13:30:41.065017744 +0100
@@ -60,7 +60,10 @@
ops/addfilename.cpp
ops/addinindex.cpp
ops/addpolarh.cpp
+ ops/addnonpolarh.cpp
ops/canonical.cpp
+ ops/delpolarh.cpp
+ ops/delnonpolarh.cpp
ops/gen2D.cpp
ops/fillUC.cpp
ops/forcefield.cpp
diff -aruN openbabel_svn_4712.orig/src/mol.cpp openbabel_svn_4712/src/mol.cpp
--- openbabel_svn_4712.orig/src/mol.cpp 2012-02-23 13:26:46.866327065 +0100
+++ openbabel_svn_4712/src/mol.cpp 2012-02-23 19:10:53.985955668 +0100
@@ -1876,6 +1876,36 @@
return (true);
}
+ bool OBMol::DeletePolarHydrogens()
+ {
+ OBAtom *atom;
+ vector<OBAtom*>::iterator i;
+ vector<OBAtom*> delatoms;
+
+ obErrorLog.ThrowError(__FUNCTION__,
+ "Ran OpenBabel::DeleteHydrogens -- polar",
+ obAuditMsg);
+
+ for (atom = BeginAtom(i);atom;atom = NextAtom(i))
+ if (atom->IsPolarHydrogen())
+ delatoms.push_back(atom);
+
+ if (delatoms.empty())
+ return(true);
+
+ IncrementMod();
+
+ for (i = delatoms.begin();i != delatoms.end();++i)
+ DeleteAtom((OBAtom *)*i);
+
+ DecrementMod();
+
+ UnsetSSSRPerceived();
+ UnsetLSSRPerceived();
+ return(true);
+ }
+
+
bool OBMol::DeleteNonPolarHydrogens()
{
OBAtom *atom;
@@ -2039,7 +2069,15 @@
return(true);
}
- bool OBMol::AddHydrogens(bool polaronly,bool correctForPH, double pH)
+ /*
+ this has become a wrapper for backward compatibility
+ */
+ bool OBMol::AddHydrogens(bool polaronly, bool correctForPH, double pH)
+ {
+ return(AddNewHydrogens(polaronly ? PolarHydrogen : AllHydrogen, correctForPH, pH));
+ }
+
+ bool OBMol::AddNewHydrogens(HydrogenType whichHydrogen, bool correctForPH, double pH)
{
if (!IsCorrectedForPH() && correctForPH)
CorrectForPH(pH);
@@ -2060,12 +2098,15 @@
return true;
}
*/
- if (!polaronly)
+ if (whichHydrogen == AllHydrogen)
obErrorLog.ThrowError(__FUNCTION__,
"Ran OpenBabel::AddHydrogens", obAuditMsg);
- else
+ else if (whichHydrogen == PolarHydrogen)
obErrorLog.ThrowError(__FUNCTION__,
"Ran OpenBabel::AddHydrogens -- polar only", obAuditMsg);
+ else
+ obErrorLog.ThrowError(__FUNCTION__,
+ "Ran OpenBabel::AddHydrogens -- nonpolar only", obAuditMsg);
// Make sure we have conformers (PR#1665519)
if (!_vconf.empty()) {
@@ -2086,7 +2127,12 @@
vector<OBAtom*>::iterator i;
for (atom = BeginAtom(i);atom;atom = NextAtom(i))
{
- if (polaronly && !(atom->IsNitrogen() || atom->IsOxygen() ||
+ if (whichHydrogen == PolarHydrogen
+ && !(atom->IsNitrogen() || atom->IsOxygen() ||
+ atom->IsSulfur() || atom->IsPhosphorus()))
+ continue;
+ if (whichHydrogen == NonPolarHydrogen
+ && (atom->IsNitrogen() || atom->IsOxygen() ||
atom->IsSulfur() || atom->IsPhosphorus()))
continue;
@@ -2209,7 +2255,12 @@
bool OBMol::AddPolarHydrogens()
{
- return(AddHydrogens(true));
+ return(AddNewHydrogens(PolarHydrogen));
+ }
+
+ bool OBMol::AddNonPolarHydrogens()
+ {
+ return(AddNewHydrogens(NonPolarHydrogen));
}
bool OBMol::AddHydrogens(OBAtom *atom)
diff -aruN openbabel_svn_4712.orig/src/ops/addnonpolarh.cpp openbabel_svn_4712/src/ops/addnonpolarh.cpp
--- openbabel_svn_4712.orig/src/ops/addnonpolarh.cpp 1970-01-01 01:00:00.000000000 +0100
+++ openbabel_svn_4712/src/ops/addnonpolarh.cpp 2012-02-23 13:49:21.600952935 +0100
@@ -0,0 +1,50 @@
+/**********************************************************************
+AddNonPolarH.cpp - The option --AddNonPolarH adds hydrogen to polar atoms only.
+
+Copyright(C) 2007 by Chris Morley
+
+This file is part of the Open Babel project.
+For more information, see <http://openbabel.org/>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation version 2 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+***********************************************************************/
+#include <openbabel/babelconfig.h>
+#include <iostream>
+#include<openbabel/op.h>
+#include<openbabel/mol.h>
+
+namespace OpenBabel
+{
+
+class OpAddNonPolarH : public OBOp
+{
+public:
+ OpAddNonPolarH(const char* ID) : OBOp(ID, false){};
+ const char* Description(){ return "Adds hydrogen to nonpolar atoms only"; }
+
+ virtual bool WorksWith(OBBase* pOb)const{ return dynamic_cast<OBMol*>(pOb)!=NULL; }
+ virtual bool Do(OBBase* pOb, const char* OptionText=NULL, OpMap* pOptions=NULL, OBConversion* pConv=NULL);
+};
+
+/////////////////////////////////////////////////////////////////
+OpAddNonPolarH theOpAddNonPolarH("AddNonPolarH"); //Global instance
+
+/////////////////////////////////////////////////////////////////
+bool OpAddNonPolarH::Do(OBBase* pOb, const char* OptionText, OpMap* pOptions, OBConversion* pConv)
+{
+ OBMol* pmol = dynamic_cast<OBMol*>(pOb);
+ if(!pmol)
+ return false;
+
+ pmol->AddNonPolarHydrogens();
+
+ return true;
+}
+}//namespace
diff -aruN openbabel_svn_4712.orig/src/ops/addpolarh.cpp openbabel_svn_4712/src/ops/addpolarh.cpp
--- openbabel_svn_4712.orig/src/ops/addpolarh.cpp 2012-02-23 13:25:54.736955153 +0100
+++ openbabel_svn_4712/src/ops/addpolarh.cpp 2012-02-23 13:49:31.131005754 +0100
@@ -43,7 +43,7 @@
if(!pmol)
return false;
- pmol->AddHydrogens(true, false);
+ pmol->AddPolarHydrogens();
return true;
}
diff -aruN openbabel_svn_4712.orig/src/ops/delnonpolarh.cpp openbabel_svn_4712/src/ops/delnonpolarh.cpp
--- openbabel_svn_4712.orig/src/ops/delnonpolarh.cpp 1970-01-01 01:00:00.000000000 +0100
+++ openbabel_svn_4712/src/ops/delnonpolarh.cpp 2012-02-23 13:33:07.804952208 +0100
@@ -0,0 +1,50 @@
+/**********************************************************************
+DelNonPolarH.cpp - The option --DelNonPolarH deletes hydrogen from polar atoms only.
+
+Copyright(C) 2007 by Chris Morley
+
+This file is part of the Open Babel project.
+For more information, see <http://openbabel.org/>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation version 2 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+***********************************************************************/
+#include <openbabel/babelconfig.h>
+#include <iostream>
+#include<openbabel/op.h>
+#include<openbabel/mol.h>
+
+namespace OpenBabel
+{
+
+class OpDelNonPolarH : public OBOp
+{
+public:
+ OpDelNonPolarH(const char* ID) : OBOp(ID, false){};
+ const char* Description(){ return "Deletes hydrogen from nonpolar atoms only"; }
+
+ virtual bool WorksWith(OBBase* pOb)const{ return dynamic_cast<OBMol*>(pOb)!=NULL; }
+ virtual bool Do(OBBase* pOb, const char* OptionText=NULL, OpMap* pOptions=NULL, OBConversion* pConv=NULL);
+};
+
+/////////////////////////////////////////////////////////////////
+OpDelNonPolarH theOpDelNonPolarH("DelNonPolarH"); //Global instance
+
+/////////////////////////////////////////////////////////////////
+bool OpDelNonPolarH::Do(OBBase* pOb, const char* OptionText, OpMap* pOptions, OBConversion* pConv)
+{
+ OBMol* pmol = dynamic_cast<OBMol*>(pOb);
+ if(!pmol)
+ return false;
+
+ pmol->DeleteNonPolarHydrogens();
+
+ return true;
+}
+}//namespace
diff -aruN openbabel_svn_4712.orig/src/ops/delpolarh.cpp openbabel_svn_4712/src/ops/delpolarh.cpp
--- openbabel_svn_4712.orig/src/ops/delpolarh.cpp 1970-01-01 01:00:00.000000000 +0100
+++ openbabel_svn_4712/src/ops/delpolarh.cpp 2012-02-23 13:33:11.127991210 +0100
@@ -0,0 +1,50 @@
+/**********************************************************************
+DelPolarH.cpp - The option --DelPolarH deletes hydrogen from polar atoms only.
+
+Copyright(C) 2007 by Chris Morley
+
+This file is part of the Open Babel project.
+For more information, see <http://openbabel.org/>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation version 2 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+***********************************************************************/
+#include <openbabel/babelconfig.h>
+#include <iostream>
+#include<openbabel/op.h>
+#include<openbabel/mol.h>
+
+namespace OpenBabel
+{
+
+class OpDelPolarH : public OBOp
+{
+public:
+ OpDelPolarH(const char* ID) : OBOp(ID, false){};
+ const char* Description(){ return "Deletes hydrogen from polar atoms only"; }
+
+ virtual bool WorksWith(OBBase* pOb)const{ return dynamic_cast<OBMol*>(pOb)!=NULL; }
+ virtual bool Do(OBBase* pOb, const char* OptionText=NULL, OpMap* pOptions=NULL, OBConversion* pConv=NULL);
+};
+
+/////////////////////////////////////////////////////////////////
+OpDelPolarH theOpDelPolarH("DelPolarH"); //Global instance
+
+/////////////////////////////////////////////////////////////////
+bool OpDelPolarH::Do(OBBase* pOb, const char* OptionText, OpMap* pOptions, OBConversion* pConv)
+{
+ OBMol* pmol = dynamic_cast<OBMol*>(pOb);
+ if(!pmol)
+ return false;
+
+ pmol->DeletePolarHydrogens();
+
+ return true;
+}
+}//namespace
diff -aruN openbabel_svn_4712.orig/src/plugin.cpp openbabel_svn_4712/src/plugin.cpp
--- openbabel_svn_4712.orig/src/plugin.cpp 2012-02-23 13:26:46.859326950 +0100
+++ openbabel_svn_4712/src/plugin.cpp 2012-02-23 13:34:06.171957558 +0100
@@ -383,7 +383,10 @@
// operations
plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpAddInIndex)->GetID());
plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpAddPolarH)->GetID());
+ plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpAddNonPolarH)->GetID());
plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpCanonical)->GetID());
+ plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpDelPolarH)->GetID());
+ plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpDelNonPolarH)->GetID());
plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpFillUC)->GetID());
plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpEnergy)->GetID());
plugin_ids.push_back(reinterpret_cast<OBPlugin*>(&theOpMinimize)->GetID());
diff -aruN openbabel_svn_4712.orig/include/openbabel/mol.h openbabel_svn_4712/include/openbabel/mol.h
--- openbabel_svn_4712.orig/include/openbabel/mol.h 2012-02-23 13:25:46.435951896 +0100
+++ openbabel_svn_4712/include/openbabel/mol.h 2012-02-23 19:13:21.378046002 +0100
@@ -107,6 +107,8 @@
// flags 22-32 unspecified
#define OB_CURRENT_CONFORMER -1
+enum HydrogenType { AllHydrogen, PolarHydrogen, NonPolarHydrogen };
+
// class introduction in mol.cpp
class OBAPI OBMol: public OBBase
{
@@ -461,6 +463,9 @@
//! Delete all hydrogens from the supplied atom
//! \return Success
bool DeleteHydrogens(OBAtom*);
+ //! Delete all hydrogen atoms connected to a polar atom
+ //! \see OBAtom::IsPolarHydrogen
+ bool DeletePolarHydrogens();
//! Delete all hydrogen atoms connected to a non-polar atom
//! \see OBAtom::IsNonPolarHydrogen
bool DeleteNonPolarHydrogens();
@@ -478,6 +483,10 @@
bool AddHydrogens(OBAtom*);
//! Add only polar hydrogens (i.e., attached to polar atoms, not C)
bool AddPolarHydrogens();
+ //! Add only nonpolar hydrogens (i.e., attached to C)
+ bool AddNonPolarHydrogens();
+ //! Add polar and/or nonpolar hydrogens
+ bool AddNewHydrogens(HydrogenType whichHydrogen, bool correctForPH=false, double pH=7.4);
//! If @p threshold is not specified or is zero, remove all but the largest
//! contiguous fragment. If @p threshold is non-zero, remove any fragments with fewer
diff -aruN openbabel_svn_4712.orig/include/openbabel/plugin.h openbabel_svn_4712/include/openbabel/plugin.h
--- openbabel_svn_4712.orig/include/openbabel/plugin.h 2012-02-23 13:25:46.428951870 +0100
+++ openbabel_svn_4712/include/openbabel/plugin.h 2012-02-23 13:44:46.112960295 +0100
@@ -535,7 +535,10 @@
// operations
OB_STATIC_PLUGIN(OpAddInIndex, theOpAddInIndex)
OB_STATIC_PLUGIN(OpAddPolarH, theOpAddPolarH)
+ OB_STATIC_PLUGIN(OpAddNonPolarH, theOpAddNonPolarH)
OB_STATIC_PLUGIN(OpCanonical, theOpCanonical)
+ OB_STATIC_PLUGIN(OpDelPolarH, theOpDelPolarH)
+ OB_STATIC_PLUGIN(OpDelNonPolarH, theOpDelNonPolarH)
OB_STATIC_PLUGIN(OpFillUC, theOpFillUC)
OB_STATIC_PLUGIN(OpEnergy, theOpEnergy)
OB_STATIC_PLUGIN(OpMinimize, theOpMinimize)
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel