| 1 |
/********************************************************************** |
| 2 |
transform.cpp - Perform command-line requested transformations |
| 3 |
|
| 4 |
Copyright (C) 2004-2005 by Chris Morley |
| 5 |
|
| 6 |
This file is part of the Open Babel project. |
| 7 |
For more information, see <http://openbabel.sourceforge.net/> |
| 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 |
|
| 19 |
#include "mol.hpp" |
| 20 |
#include <iostream> |
| 21 |
|
| 22 |
using namespace std; |
| 23 |
namespace OpenBabel |
| 24 |
{ |
| 25 |
|
| 26 |
OBBase* OBMol::DoTransformations(const std::map<std::string, std::string>* pOptions) |
| 27 |
{ |
| 28 |
// Perform any requested transformations |
| 29 |
// on a OBMol |
| 30 |
//The input map has option letters or name as the key and |
| 31 |
//any associated text as the value. |
| 32 |
//For normal(non-filter) transforms: |
| 33 |
// returns a pointer to the OBMol (this) if ok or NULL if not. |
| 34 |
//For filters returns a pointer to the OBMol (this) if there is a match, |
| 35 |
//and NULL when not and in addition the OBMol object is deleted NULL. |
| 36 |
|
| 37 |
//This is now a virtual function. The OBBase version just returns the OBMol pointer. |
| 38 |
//This is declared in mol.h |
| 39 |
|
| 40 |
//The filter options, s and v allow a obgrep facility. |
| 41 |
//Used together they must both be true to allow a molecule through. |
| 42 |
|
| 43 |
//Parse GeneralOptions |
| 44 |
if(pOptions->empty()) |
| 45 |
return this; |
| 46 |
|
| 47 |
int ret=1; |
| 48 |
bool smatch=true, vmatch=true; |
| 49 |
|
| 50 |
map<string,string>::const_iterator itr; |
| 51 |
|
| 52 |
if(pOptions->find("b")!=pOptions->end()) |
| 53 |
ret=ConvertDativeBonds(); |
| 54 |
|
| 55 |
if(pOptions->find("d")!=pOptions->end()) |
| 56 |
ret=DeleteHydrogens(); |
| 57 |
|
| 58 |
if(pOptions->find("h")!=pOptions->end()) |
| 59 |
ret=AddHydrogens(false, false); |
| 60 |
|
| 61 |
if(pOptions->find("p")!=pOptions->end()) |
| 62 |
ret=AddHydrogens(false, true); |
| 63 |
|
| 64 |
if(pOptions->find("c")!=pOptions->end()) |
| 65 |
{ |
| 66 |
Center(); |
| 67 |
ret=1; |
| 68 |
} |
| 69 |
|
| 70 |
itr = pOptions->find("addtotitle"); //Appends text to title |
| 71 |
if(itr!=pOptions->end()) |
| 72 |
{ |
| 73 |
string title(GetTitle()); |
| 74 |
title += itr->second; |
| 75 |
SetTitle(title.c_str()); |
| 76 |
ret=1; |
| 77 |
} |
| 78 |
|
| 79 |
itr = pOptions->find("v"); |
| 80 |
if(itr!=pOptions->end()) |
| 81 |
{ |
| 82 |
//inverse match quoted SMARTS string which follows |
| 83 |
OBSmartsPattern sp; |
| 84 |
sp.Init(itr->second); |
| 85 |
vmatch = !sp.Match(*this); //(*pmol) ; |
| 86 |
} |
| 87 |
|
| 88 |
itr = pOptions->find("s"); |
| 89 |
if(itr!=pOptions->end()) |
| 90 |
{ |
| 91 |
//match quoted SMARTS string which follows |
| 92 |
OBSmartsPattern sp; |
| 93 |
sp.Init(itr->second.c_str()); |
| 94 |
smatch = sp.Match(*this); //(*pmol) ; |
| 95 |
} |
| 96 |
|
| 97 |
if(!smatch || !vmatch) |
| 98 |
{ |
| 99 |
//filter failed: delete OBMol and return NULL |
| 100 |
delete this; |
| 101 |
return NULL; |
| 102 |
} |
| 103 |
else |
| 104 |
return ret ? this : NULL; |
| 105 |
} |
| 106 |
|
| 107 |
/////////////////////////////////////////////////// |
| 108 |
const char* OBMol::ClassDescription() |
| 109 |
{ |
| 110 |
return "For conversions of molecules\n \ |
| 111 |
Additional options :\n \ |
| 112 |
-d Delete Hydrogens\n \ |
| 113 |
-h Add Hydrogens\n \ |
| 114 |
-p Add Hydrogens appropriate for pH\n \ |
| 115 |
-b Convert dative bonds e.g.[N+]([O-])=O to N(=O)=O\n \ |
| 116 |
-c Center Coordinates\n \ |
| 117 |
-j Join all input molecules into a single output molecule\n \ |
| 118 |
-s\"smarts\" Convert only molecules matching SMARTS:\n \ |
| 119 |
-v\"smarts\" Convert only molecules NOT matching SMARTS:\n\n" ; |
| 120 |
} |
| 121 |
|
| 122 |
} //namespace OpenBabel |
| 123 |
|
| 124 |
//! \file transform.cpp |
| 125 |
//! \brief Perform command-line requested transformations for OBMol |
| 126 |
//! and SMARTS filtering |