OpenBabelDocumentation,Release2.3.1
5. If,afterupdating,thecompilationfailspleasereportittotheOpenBabelmailinglist.Inthemeanwhile,ifyou
wanttogobacktoaparticularrevision(thatis,ifyoudon’twanttousethelatestone),justusesvn infoto
findthenumberofthecurrentrevision,andupdatetoanearlierrevisioneitherbydateorbyrevisionnumber:
$ svn n info
...
Revision: 1740
...
$ svn n update -r 1735
(or)
$ svn n update -r {2007-01-01}
UsefulSubversionCommands
ThefollowingtablesuggestsSubversioncommandsusefulforOpenBabelcontributors.Moredocumentationcanbe
foundintheOfficialSVNManual. Inthefollowingexamples,reposhouldbereplacedbythefullURLtotheOpen
Babelsubversionrepository(https://openbabel.svn.sourceforge.net/svnroot/openbabel/openbabel).
SubversionCommand
Whatitdoes
svn co repo/trunk
CheckoutthelatestdevelopmentversionofOpenBabel
svn update
Updatethecurrentdirectoryandsubdirectorieswithanynewchanges
svn add filename
Addthefilefilenametotherepository
svn remove filename
Removethefilefilename(beforeacommit)
svn mv filename newname
Move/renamethefilefilenametonewname
svn commit
Committhechangestothecentralrepository
svn diff
Returnadiffsetofdifferencesbetweentheworkingcopyandthecentral
repository
svn switch
repo/branches/foo
Switchthecurrentworkingcopytoabranchnamedfoo
svn copy
repo/branches/foo
Createabranchnamedfoowiththecurrentworkingcopy
PatchesandChangesets
We’rehuman–it’smucheasiertounderstandexactlywhatapatchisdoingifit’snottryingtoadd20featuresorfix
20bugsatonce. (Hopefullytherewon’tbeaneedtofix20bugs!)Ifyouwanttoaddseveralfeaturesorfixseveral
bugs,breakthepatchupintooneforeachrequest.Thefastersomeonecanunderstandyourpatch,thefasteritwillgo
intothesource.Everyonebenefitsfromfaster,qualitydevelopment.
Similarly, it’ssometimesnecessarytorevertthecodetoanolderversionbecauseofbugs. . Eachsetofchanges
shouldonlytouchasfewfilesasareneeded. Thismakesiteasierforotherstoreviewyourchangesandundothem
ifnecessarily. (Again,hopefullythere’sneveraneed,butthisiscertainlya“bestpractice”tomakelifeeasierfor
everyone.)
10.2.3 MonitoringProgress
Developersshouldkeeptrackofchangesmadebyothers. Likemostopensourceprojects,developmentoccursin
manyplacesbymanycontributors. Thereforeitisimportanttokeepup-to-datewithyourcoderepositoryandkeep
ontopofchangesmadebyothers.Abugyoujustfoundinthelatestreleasemayhavealreadybeenfixedbysomeone
else.
• CIAStatsonOpenBabel(providesawebpageandRSSfeedforeverychange)
• OpenBabel-Updatesmailinglist(receivesane-mailmessageoneverychange)
10.2. DevelopingOpenBabel
95
Pdf format specification - Split, seperate PDF into multiple files in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Explain How to Split PDF Document in Visual C#.NET Application
cannot print pdf no pages selected; pdf split file
Pdf format specification - VB.NET PDF File Split Library: Split, seperate PDF into multiple files in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Splitter Control to Disassemble PDF Document
break a pdf password; break apart pdf
OpenBabelDocumentation,Release2.3.1
Ingeneral,ifyoufindthatarecentupdatebyanotherdeveloperhasintroducedbugsorbrokenthecode,pleasebring
itupwiththemASAP.Wehaveapolicyof“ifyoubreakit,youfixit”tokeepthesourcecoderepositoryalwaysina
workingstate.
10.2.4 Modulardesignofcodebase
Sinceversion2.0,OpenBabelhashadamodularstructure.ParticularlyfortheuseofOpenBabelasachemicalfile
formatconverter,itaimsto:
• separatethechemistry,theconversionprocessandtheuserinterfaces,reducing,asfaraspossible,thedepen-
dencyofoneonanother.
• putallthecodeforeachchemicalformatinoneplace(usuallyasinglecppfile)andmaketheadditionofnew
formatssimple.
• allowtheformatconversionofnotjustmolecules,butalsoanyotherchemicalobjects,suchasreactions.
Figure10.1:ThestructureoftheOpenBabelcodebasebrokendownintomodules
TheseparatepartsoftheOpenBabelprogramare:
96
Chapter10. ContributingtoOpenBabel
TIFF Image Viewer| What is TIFF
The TIFF specification contains two parts: Baseline TIFF (the edit and processing images with TIFF format and other such as Bitmap, Png, Gif, Tiff, PDF, MS-Word
break apart pdf pages; acrobat split pdf pages
DocImage SDK for .NET: Web Document Image Viewer Online Demo
Microsoft PowerPoint: PPTX, PPS, PPSX; PDF: Portable Document Format; TIFF: Tagged Image File Format; XPS: XML Paper Specification. Supported Browers: IE9+;
can't cut and paste from pdf; reader split pdf
OpenBabelDocumentation,Release2.3.1
• TheChemicalcore,whichcontainsOBMoletc.andhasallthechemicalstructuredescriptionandmanipulation.
ThisbitistheheartoftheapplicationanditsAPIcanbeusedasachemicaltoolbox. Ithasnoinput/output
capabilities.
• TheFormats,whichreadandwritetofilesofdifferenttypes. . Theseclassesarederivedfromacommonbase
class,OBFormat,whichisintheConversionControlmodule.Theyalsomakeuseofthechemicalroutinesin
theChemicalCoremodule. Eachformatfilecontainsaglobalobjectoftheformatclass. . Whentheformatis
loadedtheclassconstructorregistersthepresenceoftheclasswithOBConversion.Thismeanstheformatsare
plugins-newformatscanbeaddedwithoutchanginganyframeworkcode.
• CommonFormatsincludeOBMoleculeFormatsandXMLBaseFormatfromwhichmostotherformats(like
FormatAandFormatBinthediagram)arederived.IndependentformatslikeFormatCarealsopossible.
• TheConversioncontrol,whichalsokeepstrackoftheavailableformats,theconversionoptionsandtheinput
andoutputstreams. Itcanbecompiledwithoutreferencetoanyotherpartsoftheprogram. . Inparticular,it
knowsnothingoftheChemicalcore:mol.hisnotincluded.
• TheUserinterface,whichmaybeacommandline(inmain.cpp),aGraphicalUserInterface(GUI),especially
suitedtoWindowsusersandnovices,ormaybepartofanotherprogramwhichusesOpenBabel’sinputand
outputfacilities. ThisdependsonlyontheConversioncontrolmodule(obconversion.hisincluded),butnoton
theChemicalcoreoronanyoftheFormats.
• TheFingerprintAPI,aswellasbeingusableinexternalprograms,isemployedbythefastsearchandfingerprint
formats.
• TheFingerprints,whicharebitarrayswhichdescribeanobjectandwhichfacilitatefastsearching. . Theyare
alsobuiltasplugins,registeringthemselveswiththeirbaseclassOBFingerprintwhichisintheFingerprintAPI.
• TheErrorhandlingcanbeusedthroughouttheprogramtologanddisplayerrorsandwarnings(seebelow).
ItispossibletobuildeachboxinthediagramasaseparateDLLorsharedlibraryandtherestricteddependenciescan
helptolimittheamountofrecompilation.Fortheformatsorthefingerprintsbuiltinthiswayitmaybepossibletouse
onlythosewhoseDLLorsofilesarepresentwhentheprogramstarts.Severalformatsorfingerprintsmaybepresent
inasingledynamiclibrary.
Alternatively,andmostcommonly,thesamesourcecodecanbebuiltintoasingleexecutable.Therestricteddepen-
denciesstillprovideeasierprogrammaintenance.
Thissegregationmeansthatamodulecandirectlycallcodeonlyinothermodulesconnectedtoitbyforwardarrows.
Sosomedisciplineisneededwhenaddingnewcode,andsometimesnon-obviouswork-aroundsarenecessary. For
instance,sincetheuserinterfacedoesn’tknowabouttheChemicalCore,ifitwerenecessarytosetanyparametersin
it,thenthiswouldhavetobedonethroughapseudoformatOBAPIInterface.
Sometimesoneformatneedstousecodefromanotherformat,forexample,rxnformatneedstoreadmolfileswith
codefrommdlformat. ThecallingformatshouldnotusethecodedirectlybutshoulddoitthroughaOBConversion
objectconfiguredwiththeappropriatehelperformat.
TheobjectspassedbetweenthemodulesinthediagramabovearepolymorphicOBBasepointers.Thismeansthatthe
conversionframeworkcanbeusedbyanyobjectderivedfromOBBase(whichessentiallymeansanything-chemical
ornot).MostcommonlytheserefertoOBMolobjects,lesscommonlytoOBReactionobjects,butcouldbeextended
toanythingelsewithoutneedingtochangeanyexistingcode.
10.2.5 ErrorHandlingandWarnings
ThegeneralphilosophyoftheOpenBabelprojectistoattempttogracefullyrecoverfromerrorconditions.Depending
ontheseverityoftheerror,amessagemayormaynotbesenttotheuser–userscanfilteroutdeveloperdebugging
messagesandminorerrors,butshouldbenotifiedofsignificantproblems.
ErrorsandwarningsinOpenBabelarehandledinternallybyaflexiblesystemmotivatedbyafewfactors:
10.2. DevelopingOpenBabel
97
GIF Image Viewer| What is GIF
routines according to the latest GIF specification to meet edit and processing images with Gif format and other such as Bitmap, Png, Gif, Tiff, PDF, MS-Word
break password pdf; pdf format specification
C# Imaging - C# Code 128 Generation Guide
minimum left and right margins that go with specification. load a program with an incorrect format", please check Create Code 128 on PDF, Multi-Page TIFF, Word
pdf no pages selected to print; break pdf password online
OpenBabelDocumentation,Release2.3.1
• Endusersoftendonotwishtobedelugedbydebuggingorothermessagesduringoperation.
• Otherdevelopersmaywishtoredirectorfiltererror/warningoutput(e.g.,inaGUI).
• TheoperationofOpenBabelshouldbeopentodevelopersandusersaliketomonitoran“audittrail”ofopera-
tionsonfilesandmolecules,anddebugtheprogramandlibraryitselfwhentheneedarises.
Multipleerror/warninglevelsexistandshouldbeusedbycode. ThesearedefinedintheobMessageLevelenumas
follows:
• obError–forcriticalerrors(e.g.,cannotreadafile)
• obWarning–fornon-criticalproblems(e.g.,moleculeappearsempty)
• obInfo–forinformativemessages(e.g.,fileisanon-standardformat)
• obAuditMsg–formessagesauditingmethodswhichdestroyorperceivemoleculardata(e.g.,kekulization,
atomtyping,etc.)
• obDebug–formessagesonlyusefulfordebuggingpurposes
ThedefaultfilterlevelissettoobWarning,whichmeansthatusersaretoldofcriticalerrors,butnotnon-standard
formattingofinputfiles.
AglobalerrorhandlerobErrorLog(aninstanceofOBMessageHandler)isdefinedandshouldbeusedasshowninthe
APIdocumentationfortheOBMessageHandlerclass.
10.2.6 LazyEvaluation
TheOBMol::BeginModify()andOBMol::EndModify()callsarepartofOpenBabel’slazyevaluationmechanism.
Insomecases,codemaydesiretomakealargenumberofchangestoanOBMolobjectatonce.Ideally,thisshouldall
happenwithouttriggeringunintendedperceptionroutines.Therefore,theBeginModify()callmarksthebeginning
ofsuchcode,andEndModify()triggersanyneededupdatesoflazyevaluationmethods.
Forexample:
mol.BeginModify();
double x,y,z;
OBAtom
*
atom;
vector<stringvs;
for (i 1; i <= natoms; i ++)
{
if (!ifs.getline(buffer,BUFF_SIZE))
return(false);
tokenize(vs,buffer);
if (vs.size() != 4)
return(false);
atom mol.NewAtom();
atof((char
*
)vs[1].c_str());
atof((char
*
)vs[2].c_str());
atof((char
*
)vs[3].c_str());
atom->SetVector(x,y,z); //set coordinates
atom->SetAtomicNum(atoi(vs[0].c_str())); // set atomic number
}
mol.ConnectTheDots();
mol.PerceiveBondOrders();
mol.EndModify();
98
Chapter10. ContributingtoOpenBabel
VB Imaging - EAN-8 Generating Tutorial
compatible with the latest GS1 General Specification, with the Besides the PNG image format, other supported common 8 on defined page area of a PDF, multi-page
pdf file specification; pdf rotate single page
VB.NET Image: Create Code 11 Barcode on Picture & Document Using
REFile.SaveDocumentFile(doc, "c:/code11.pdf", New PDFEncoder()). Data, Valid: 0-9, -, Format, PNG GIF JPEG. to the ISO/IEC international specification, the minimum
can't select text in pdf file; split pdf into individual pages
OpenBabelDocumentation,Release2.3.1
ThiscodereadsinalistofatomswithXYZcoordinatesandtheatomicnumberinthefirstcolumn(vs[0]). Since
hundredsorthousandsofatomscouldbeaddedtoamolecule,followedbycreatingbonds,thecodeisenclosedina
BeginModify()/EndModify()pair.
10.3 Documentation
DocumentingOpenBabelisanimportantandongoingtask. Asanopensourceproject,codemustbedocumented,
bothforotherdeveloperstousetheAPIandforotherstofollowyourcode.Thisincludescleardocumentationonthe
interfacesofparticularclassesandmethods(thatis,theAPIdocumentation)butalsotutorialsandexamplesofusing
theOpenBabellibrarytoaccomplishcleartasks.
Beyondthedocumentationdescribedabove,asanopen-sourceprojectinvolvingmany,manycontributors,theinternal
codeshouldbeclearlycommentedandeasytoread(inEnglish,preferably,sincethisisthecommonlanguageof
developersontheproject).
10.3.1 AddingNewCode
Thegoldenruleiswritethedocumentation,thencodetothespecs.
Youshouldnever,everstartwritingcodeunlessyou’vespecified,clearlyandexactly,whatyourcodewilldo. This
makeslifeeasierforyou(i.e.,youknowexactlywhatthecodeshoulddo),andforothersreadingyourcode.
Thismantraalsofacilitateswritingtests(seeTestingtheCode).
10.3.2 ModifyingOldCode
Whenmodifyingoldcode,pleasetakealittletimetoimprovethedocumentationofthefunction.
Evenan“obvious”functionmustbedocumented,iffornootherreasonthantosay,“Thisfunctiondoeswhatyou
think,andhasnosideeffects.”
TakeOBAtom::SetAtomicNum()-shouldbe“obvious”,right?Wrong.
• Doesitaffectthecharge?
• Thespinmultiplicity?
• Theimplicitvalence?
• Thehybridization?
• WhathappensifIdoSetHybridization(3)andthenSetAtomicNum(1)?
• Doesthemoleculehavetobeinthemodifystate?
• Ifthemoleculeisnotinthemodifystate,isitputintothemodifystatebySetAtomicNum()?
• DoesSetAtomicNum()causearecomputationofaromaticity?
10.3.3 ChangeLogentries
TheChangeLogfileisusedtomaintainanabbreviatedhistoryofchangestothecodebyallusers. Pleaseadda
ChangeLogentrytoanypatchandmakesuretokeepituptodateasyoucommitchangestothesourcecode. The
formatshouldbemostlyself-explanatory.
Inparticular,pleaseincludeanotationofanyfileyouhavechanged. Thismakesiteasyforotherstotrackwhich
changesmayhaveaddednewfunctionality,fixedbugs,orinadvertentlycausederrors.
10.3. Documentation
99
C# Imaging - QR Code Image Generation Tutorial
to draw, insert QR Codes in PDF, TIFF, MS C# code to adjust bar code image format, location, resolution ISO+IEC+18004 QR Code bar code symbology specification.
break a pdf into multiple files; add page break to pdf
C# Imaging - EAN-8 Generating Tutorial
compatible with the latest GS1 General Specification, with the Besides the PNG image format, other supported common 8 on defined page area of a PDF, multi-page
break pdf password; split pdf files
OpenBabelDocumentation,Release2.3.1
10.3.4 Userdocumentationandtutorials
There’snopointspendingtimeaddingnewfeaturestoOpenBabelunlessyoudescribehowtousethemandgive
examples.Thebestplacetodothisisintheuserdocumentation...whichyou’rereadingrightnow.
Thisdocumentationisautomaticallygeneratedfromtextfilesinasimplemarkuplanguage(reStructuredText)using
theSphinxdocumentationsystem. Thisallowsustogeneratewebpages,PDFfiles,andevenePubeBooksallfrom
thesamesource(whichiscurrentlymaintainedatBitBucket).
Ifyounoticeanyerrorsorfeellikeaddingasection,pleaseletusknowatopenbabel-devel.
10.4 TestingtheCode
TestingisanotherimportantongoingtaskforanylargecodebasesuchasOpenBabel.Thefollowingdocumentation
isintendedtogivesomeideaastothetypesoftestsusedbyOpenBabelandvarioustoolsavailablefordebuggingand
testing.
10.4.1 TypesofTests
Unittests Thesetestscoverspecificfunctionalityofthelibrary.
Unittestsattempttoshowthatfunctionsworkasindicated(i.e. pass)andfailproperlyonunacceptableinput.
Theyarerunafterbuildingthecodebycallingmake test. . Ideallythesetestsshouldcovereverypublic
functionintheOpenBabelAPI.Addingmoreteststoprovidegreatercoverageisahighpriority.
Regressiontests Thesetestsareassociatedwithparticularbugfixes.
Aregressiontestensuresthatabug,oncefixed,staysfixed.Ifyouhavespenttimefixingabug,it’sworthwhile
towriteanassociatedregressiontest.Infact,writingthetestfirstistoagoodwaytoprovethatyouhaveinfact
fixedtheproblem.
Roundtriptests Testfiletranslation.
Thesearerunfromthetestfilerepositoryandtestfiletranslationto/fromfileformats.
“Dogfood”tests Usingthedevelopmentcode.
Manyofthedevelopersusethecurrentdevelopmentsnapshotsfortheirdailyuse. Thisissometimescalled
eatingyourowndogfoodandensuresthatbugswhichimpactcommonfunctionalityarecaughtquickly.
Scriptinglanguagetests PerlandPythonunittests
BoththePerlandPythonlanguagebindingshaveadditionalteststoensurethatthesescriptinglanguagemodules
work.Thesetestsnotonlystressthescriptingmodulesthemselves,butalsotheunderlyinglibrary.
10.4.2 Testdashboard
WehavesetupatestdashboardwithnightlybuildsofOpenBabelforseveralcompilersandoperatingsystems.
ThedashboardallowsproblemswithparticularSVNcommitstobeeasilyidentified. Developersshouldcheckthe
dashboardaftercommittingcodeandcheckwhetherthetestsuitehasfailed.
WethankKitWareforprovidingdashboardresources.
10.4.3 Toolsforsoftwaretesting
Avarietyoftoolscanbeusedtohelpdiagnoseproblemsanddebugerrors:
100
Chapter10. ContributingtoOpenBabel
VB Imaging - Micro PDF 417 VB Barcode Generation
with established ISO/IEC barcode specification and standard You can easily generator Micro PDF 417 barcode and a program with an incorrect format", please check
acrobat split pdf into multiple files; pdf split and merge
GS1-128 C#.NET Integration Tutoria
by GS1 in its system standards using Code 128 barcode specification. text //Generate EAN 128 barcodes in GIF image format ean128.generateBarcodeToImageFile
c# split pdf; pdf link to specific page
OpenBabelDocumentation,Release2.3.1
Debuggers
gdb(theGNUprojectdebugger)isabasicdebuggeronUNIXsystems.
• GDBcanberunonthebabelprogramlikeso:./libtool l gdb src/babel
• SeveralGDBcommandsarehighlyuseful,includingbtwhichgivesafullbacktraceofprogramexecutionupon
error.
• TheuseofcodeoptimizationwhencompilingcanmakedebuggingwithGDBandotherdebuggersextremely
difficult.Ifneeded,makesureOpenBabelhasbeencompiled,e.g.withCXXFLAGS="-g -O0"onUNIX.
MemoryCheckers
UnlikelanguageslikeJava,whichhandlememoryallocationanddeletion,C++requiresthatallcodehandlememory.
Inparticular,thismeansifyouusenewormallocorsimilarcalls,youmustbesurethememorywillbeproperlyfreed
whennolongerneeded. So-called“memoryleaks”arecaseswherememoryhasbeenallocated,butneverproperly
freedandaresignificantbugsinOpenBabel.
Severaltoolscanhelpfindsucherrors:
• valgrindworksonseveralplatformsbycarefullymonitoringeachmemoryaccessandallocation.
• LeakTracerworksonarangeofplatformsbyusingC++operatoroverloading.
• MallocDebug(MacOSXonly)isagraphicfront-endtomonitormemoryuseandincorrectmemoryusage.
• VisualLeakDetector(Windows/MSVConly)isaveryeasywaytofindmemoryleaks.
CodeProfiling
Toimprovethespeedofexecution,itisoftenhelpfultorelyontoolsthatmonitorthefrequencyanddurationof
functioncalls.Thisinformationcanhelptoidentifyperformancebottlenecks.
• gprofisusedwiththeGCCcompilerstoproduceprofilingdataincludingthenumberofcallstoroutinesandthe
amountoftimespentexecuting.
• Shark/Saturn(MacOSXonly)isagraphicalfront-endstogprofandcansampleprogramswhilerunning.
• callgrindisrunthroughthevalgrindvirtualmachineusingvalgrind d --tool=callgrind ./myexe.
Thisworksbest(althoughslower)iftheexecutableiscompiledwithdebugginginformation.
C++Unscrambler
ThesymbolsusedbyC++compilersandexposedbydebugging,profiling,andmemorytoolsare“scrambled.” The
c++filtprogramcanbeusedtodecodethesymboltoahuman-readableform.
10.5 SoftwareArchaeology
Inanylargesoftwareproject,somepartsofthecodearerevisedandkeptup-to-datemorethanothers.
Conversely,somepartsofthecodebegintofallbehind–thecodemaybepoorlytested,poorlydocumented,andnot
alwaysuptobestpractices.
Withthatinmind,thefollowingsectionsdescribetheimportanttaskofsoftwarearcheology–divingintoolderparts
ofcodeandbringingthemuptodate.Whenevereditingafile,pleasekeeptheseinmind.
10.5. SoftwareArchaeology
101
OpenBabelDocumentation,Release2.3.1
10.5.1 DocumentationandCodeReadability
• Addcleardocumentationforeverypublicfunction(seeDocumentation).
• Addclearcommentsontheinternaloperationoffunctionssothatanyonecanreadthroughthecodequickly.
– Ifyou’renotsurewhatafunctiondoes,e-mailtheopenbabel-devellistanditcanbeworkedout.
• Markfunctionswhichshouldbepubliclyvisibleandfunctionswhichareonlyusefulinternally.Manymethods
arenotparticularlyusefulexceptinsidethelibraryitself.
• Improvecodeindentation
– Itseemslikeaminorpoint,buttheformatofyourcodeisimportant.Asopensourcesoftware,yourcode
isreadbymany,manypeople.
– Differentcontributionshaveoftenhaddifferentindentationstyles. . Simplymakingthecodeindentation
consistentacrossanentirefilemakesthecodeeasiertoread.
– ThecurrentacceptedschemeforOpenBabelisadefaultindentoftwospaces,anduseofspacesinstead
oftabs.
– Fortipsonchangingyoureditortousethisindentationstyle,pleasee-mailtheopenbabel-devellist.
• Deletecodewhichiscommentedout.TheSVNversioncontrolsystemmaintainshistory,soifweneeditlater,
wecangobackandgetthatcode.Deadcodelikethissimplymakesithardertoreadtheimportantcode!
• MarkingareasofcodewhichuseOBAtom::GetIdx()orotheraccessestoatomindexes,whichmaybreakwhen
atomindexingchanges.
10.5.2 CodeMaintenance
• Minimize#if/#endifconditionalcompilation. Someisrequiredforportability,buttheseshouldbemini-
mizedwherepossible. Ifthereseemstobesomemagic#definewhichaccessespartsofthefile,it’sprobably
deadcode.Asabove,deadcodemakesithardertomaintainandreadeverythingelse.
• Removingcallstocout,cerr,STDOUT,perroretc.Theseshouldusetheglobalerrorreportingcode.
• Minimizewarningsfromcompilers(e.g.,GCCflags-Wextra a -Wall).Sometimestheseareinnocuous,but
it’susuallybettertofixtheproblemsbeforetheybecomebugs.
• Usestaticcodeanalysistoolstofindpotentialbugsinthecodeandremovethem.
• Insureproperuseofatomandbonditerators, , e.g.,FOR_ATOMS_OF_MOLratherthanatom orbondindex
access,whichwillbreakifindexingchanges.
Patchesandcontributionstowardsanyofthesetaskswillbegreatlyappreciated.
102
Chapter10. ContributingtoOpenBabel
Chapter
11
Addingplugins
OpenBabelusesapluginarchitectureforfileformats,‘operations’,chargemodels,forcefields,fingerprintsandde-
scriptors. ThegeneralideabehindpluginsisdescribedonWikipedia. Whenyoustartanapplicationthatusesthe
OpenBabellibrary,itsearchesforavailablepluginsandloadsthem. Thismeans,forexample,thatpluginscouldbe
distributedseparatelytotheOpenBabeldistribution.
Infact,eventheplugintypesarethemselvesplugins;thismakesiteasytoaddnewcategoriesofplugin.Thedifferent
typesofpluginscanbelistedusing:
C:\>babel -L
charges
descriptors
fingerprints
forcefields
formats
loaders
ops
Tolistthepluginsofaparticulartype,forexample,chargemodels,justspecifytheplugintype:
C:\>babel -L L charges
gasteiger
Assign Gasteiger-Marsili i sigma partial l charges
mmff94
Assign MMFF94 4 partial l charges
qeq
Assign QEq (charge e equilibration) ) partial charges (Rappe and d Goddard, , 199
1)
qtpie
Assign QTPIE (charge e transfer, polarization and equilibration) partial
charges (Chen and Martinez, 2007)
Toaddanewpluginofanytype,thegeneralmethodisverysimple:
1. Makeacopyofanexistingplugin.cppfile
2. Edititsothatitdoeswhatyouwant
3. Addthenameofthe.cppfiletotheappropriateCMakeLists.txt.
ThefollowingsectionsdescribeindepthhowtoaddsupportforanewfileformatoroperationtoOpenBabel. Re-
memberthatifyoudoaddanewplugin,pleasecontributethecodebacktotheOpenBabelproject.
11.1 Howtoaddanewfileformat
Addingsupportforanewfileformatisarelativelyeasyprocess,particularlywithOpenBabel2.3andlater.Hereare
severalimportantstepstorememberwhendevelopingaformattranslator:
1. Createafileforyourformatinsrc/formats/orsrc/formats/xml/(forXML-basedformats).Ideally,
thisfileisself-containedalthoughseveralformatsmodulesarecompiledacrossmultiplesourcecodefiles.
103
OpenBabelDocumentation,Release2.3.1
2. Addthenameofthenew.cppfiletoanappropriateplaceinsrc/formats/CMakeLists.txt.Itwillnow
becompiledaspartofthebuildprocess.
3. Takealookatotherfileformatcode,particularlyexampleformat.cpp,whichcontainsaheavily-annotated
description of writing a new format. . XML L formats need d to take a different approach; ; see the e code e in
xcmlformat.cpporpubchemformat.cpp.
4. Whenreadinginmolecules(andthusperformingalotofmolecularmodifications)callOBMol::BeginModify()
atthebeginningandOBMol::EndModify()attheend.Thiswillensurethatperceptionroutinesdonotrunwhile
youreadinamoleculeandareresetafteryourcodefinishes(seeLazyEvaluation).
5. Currently, lazyperceptiondoes s notincludeconnectivityandbondorderassignment. . Ifyourformat t does
notincludebonds,makesuretocallOBMol::ConnectTheDots()andOBMol::PerceiveBondOrders()afterOB-
Mol::EndModify()toensurebondsareassigned.
6. Considervariousinputandoutputoptionsthatuserscansetfromthecommand-lineorGUI.Forexample,many
quantummechanicsformats(aswellasotherformatswhichdonotrecognizebonds)offerthefollowingoptions:
-asCallonlyOBMol::ConnectTheDots()(singlebondsonly)
-abNobondperception
7. MakesuretousegenericdataclasseslikeOBUnitCellandothersasappropriate.Ifyourformatstoresanysort
ofcommondatatypes,consideraddingasubclassofOBGenericDataforusebyotherformatsandusercode.
8. Pleasemakesuretoaddseveralexamplefilestothetestsetrepository.Ideally,theseshouldworkseveralareas
ofyourimportcode–intheend,themorerobustthetestset,themorestableandusefulOpenBabelwillbe.The
testfilesshouldincludeatleastoneexampleofacorrectfileandoneexampleofaninvalidfile(i.e.,something
whichwillproperlybeignoredandnotcrashbabel).
9. MakesuretodocumentyourformatusingthestringreturnedbyDescription(). . Attheminimumthis
shouldincludeadescriptionofalloptions,alongwithexamples.However,themoreinformationyouadd(e.g.
unimplementedfeatures,applicationsoftheformat,andsoforth)themoreconfidentuserswillbeinusingit.
10. That’sit!Contacttheopenbabel-discussmailinglistwithanyquestions,comments,ortocontributeyournew
formatcode.
11.2 Addingnewoperationsandoptions
Thebabelcommandlinehastheform:
babel inputfile e [outputfile] ] [options]
Thereareseveraltypesofoptions:
Optionsthatcontroltheconversionprocess Forexample-i,-oand-m
Optionsspecifictoparticularinputoroutputformats Thesearespecifiedwiththe-aand-xprefixes
Generaloptions Theseusuallyoperateonamoleculeafterithas s beenreadbytheinputformatand
beforeithasbeenwrittenbytheoutputformat.
Theonesofinterestherearethegeneraloptions.Thesecanbesingleletteroptionslike-c(whichcenterscoordinates),
ormulti-characteroptionslike--separate(whichmakesseparatemoleculesfromdisconnectedfragments). The
onesmentionedarehardwiredintothecode,butitispossibletodefinenewoptionsthatworkinasimilarway.Thisis
doneusingtheOBOpclass.
104
Chapter11. Addingplugins
Documents you may be interested
Documents you may be interested