File: group__main.shtml

package info (click to toggle)
openbabel 2.3.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 75,308 kB
  • ctags: 41,952
  • sloc: cpp: 321,252; ansic: 89,228; python: 7,262; perl: 6,418; pascal: 793; sh: 194; xml: 97; ruby: 55; makefile: 47; java: 23
file content (148 lines) | stat: -rw-r--r-- 12,837 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Getting Started</title>
<link href="/site.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="search/search.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<!--#include file="header.html" -->
<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.shtml"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.shtml"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.shtml"><span>Modules</span></a></li>
      <li><a href="namespaces.shtml"><span>Namespaces</span></a></li>
      <li><a href="annotated.shtml"><span>Classes</span></a></li>
      <li><a href="files.shtml"><span>Files</span></a></li>
      <li><a href="examples.shtml"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">Getting Started</div>  </div>
</div>
<div class="contents">


<h3><a class="anchor" id="intro"></a>Introduction to Open Babel API</h3><div class="textblock"><p>Open Babel is a full chemical software toolbox. In addition to converting file formats, it offers a complete programming library for developing chemistry software. The library is written primarily in C++ and also offers interfaces to other languages (e.g., Perl and Python) using essentially the same API.</p>
<p>The heart of Open Babel lies in the <a class="el" href="classOpenBabel_1_1OBMol.shtml">OBMol</a>, <a class="el" href="classOpenBabel_1_1OBAtom.shtml">OBAtom</a>, and <a class="el" href="classOpenBabel_1_1OBBond.shtml">OBBond</a> classes, which handle operations on atoms, bonds and molecules. Newcomers should start with looking at the <a class="el" href="classOpenBabel_1_1OBMol.shtml">OBMol</a> class, designed to store the basic information in a molecule and to perceive information about a molecule.</p>
<h2><a class="anchor" id="Lazy"></a>
Evaluation</h2>
<p>One of the key philosophies in the code is that transformations and automatic perception of properties are performed in a <a href="http://en.wikipedia.org/wiki/Lazy_evaluation">"lazy"</a> manner. That is, until you call for partial atomic charges, no charges are calculated. This ensures faster transformations of chemical data -- properties that are not needed for your code will typically not be calculated. When such data is needed, appropriate routines are called, and a "flag" is set (e.g., via <a class="el" href="classOpenBabel_1_1OBMol.shtml#adcdab8f96dc4fdc2940749e527087245">OBMol::SetFlag</a> or <a class="el" href="classOpenBabel_1_1OBAtom.shtml#adcdab8f96dc4fdc2940749e527087245" title="Sets the bitwise flag.">OBAtom::SetFlag</a> etc.) so that the code is only run once.</p>
<h2><a class="anchor" id="Arbitrary"></a>
Data</h2>
<p>Arbitrary custom data and text descriptors can be stored in any atom, bond, molecule, or residue using the <a class="el" href="classOpenBabel_1_1OBGenericData.shtml">OBGenericData</a> or <a class="el" href="classOpenBabel_1_1OBPairData.shtml">OBPairData</a> classes.</p>
<p>Conversion between various chemical file formats is accomplished through the <a class="el" href="classOpenBabel_1_1OBConversion.shtml">OBConversion</a> and <a class="el" href="classOpenBabel_1_1OBFormat.shtml">OBFormat</a> classes, often through use of the <a class="el" href="classOpenBabel_1_1OBMoleculeFormat.shtml">OBMoleculeFormat</a> subclass which is designed for easy read/write access to one or more <a class="el" href="classOpenBabel_1_1OBMol.shtml">OBMol</a> objects. The philosophy of the file format codes is to parse as much chemical information from a given file as possible (no data left behind) and ideally any perception or transformations will occur when writing to some other format later. </p>
</div>

<h3><a class="anchor" id="start"></a>Getting Started</h3><div class="textblock"><p>Not surprisingly, the Open Babel library is a full chemical toolbox. So to start out, the first example is to read in molecular file data and uses the <a class="el" href="classOpenBabel_1_1OBMol.shtml">OBMol</a>, and <a class="el" href="classOpenBabel_1_1OBConversion.shtml">OBConversion</a> classes. The <a class="el" href="classOpenBabel_1_1OBMol.shtml">former</a> is designed to store the basic information in a molecule and to perceive information and chemical properties. The <a class="el" href="classOpenBabel_1_1OBConversion.shtml">latter</a> is designed to handle conversion of a variety of data (i.e., not just molecules) and import and export.</p>
<p>This example program shows how to read in a molecule, check the number of atoms, and write a SMILES string. </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">      #include &lt;iostream.h&gt;</span>

      <span class="comment">// Include Open Babel classes for OBMol and OBConversion</span>
<span class="preprocessor">      #include &lt;<a class="code" href="mol_8h.shtml" title="Handle molecules. Declarations of OBMol, OBAtom, OBBond, OBResidue. (the main header for Open Babel)...">openbabel/mol.h</a>&gt;</span>
<span class="preprocessor">      #include &lt;<a class="code" href="obconversion_8h.shtml" title="Handle file conversions. Declaration of OBFormat, OBConversion.">openbabel/obconversion.h</a>&gt;</span>

      <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc,<span class="keywordtype">char</span> **argv)
      {
         <span class="comment">// Read from STDIN (cin) and Write to STDOUT (cout)</span>
         OBConversion conv(&amp;cin,&amp;cout);

         <span class="comment">// Try to set input format to MDL SD file</span>
         <span class="comment">// and output to SMILES</span>
         <span class="keywordflow">if</span>(conv.SetInAndOutFormats(<span class="stringliteral">&quot;SDF&quot;</span>,<span class="stringliteral">&quot;SMI&quot;</span>))
         {
            OBMol mol;
            <span class="keywordflow">if</span>(conv.Read(&amp;mol))
            {
               <span class="comment">//  ...manipulate molecule</span>
               cerr &lt;&lt; <span class="stringliteral">&quot; Molecule has: &quot;</span> &lt;&lt; mol.NumAtoms()
                    &lt;&lt; <span class="stringliteral">&quot; atoms.&quot;</span> &lt;&lt; endl;
            }

            <span class="comment">// Write SMILES to the standard output</span>
            conv-&gt;Write(&amp;mol);
         }
         <span class="keywordflow">return</span> 0; <span class="comment">// exit with success</span>
      }
</pre></div><p>All of the <a class="el" href="mainclasses.shtml">main classes</a>, including <a class="el" href="classOpenBabel_1_1OBMol.shtml" title="Molecule Class.">OBMol</a> and <a class="el" href="classOpenBabel_1_1OBConversion.shtml" title="Class to convert from one format to another.">OBConversion</a>, include example code designed to facilitate using the Open Babel code in real-world chemistry. Complete examples are provided in the doc/examples directory and <a href="examples.shtml">all these examples are included in the documentation</a>.</p>
<p>For a further list of example code, see the <a href="http://openbabel.org/wiki/Developer:Tutorial">developer tutorials</a>. This section includes examples in C++, Perl, Python, and other programming languages.</p>
<p>Also, the <code>tools</code> directory of the Open Babel source releases include a variety of programs which are intended to be more advanced examples (although usually still under 300 lines of code).</p>
<p>Please e-mail the <a href="mailto:openbabel-discuss@lists.sourceforge.net">openbabel-discuss@lists.sourceforge.net</a> mailing list if you have more questions! </p>
</div>

<h3><a class="anchor" id="other"></a>Further Information</h3><div class="textblock"><p>Open Babel is a community project. In addition to this API documentation, the website offers a variety of up-to-date and useful information for developing with the library.</p>
<p>Open Babel homepage:</p>
<ul>
<li><a href="http://openbabel.org/wiki/Develop">Developing with Open Babel</a></li>
<li><a href="http://openbabel.org/wiki/Developer:Tutorial">Developer tutorials</a></li>
<li><a href="http://openbabel.org/wiki/Contribute">Contributing to the Open Babel project</a></li>
</ul>
<p>SourceForge project pages:</p>
<ul>
<li><a href="http://sourceforge.net/projects/openbabel/">Open Babel project page</a></li>
<li><a href="http://sourceforge.net/tracker/?group_id=40728&amp;atid=428740">Bug reporter</a></li>
<li><a href="http://sourceforge.net/tracker/?group_id=40728&amp;atid=428743">Feature requests</a></li>
<li><a href="http://sourceforge.net/tracker/?group_id=40728&amp;atid=447448">File format requests</a></li>
<li><a href="http://sourceforge.net/tracker/?group_id=40728&amp;atid=428743">Mailing lists and archives</a> </li>
</ul>
</div></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- end content -->

<!--#include file="footer.html" -->

<div id="footer">
<hr size="1">
<img src="http://openbabel.org/babel256.png" width="136" height="127" alt="" style="float: left;" />
<p>This file is part of the documentation for <a href="http://openbabel.org/wiki/">Open Babel</a>, version 2.3.</p>
<div class="bottom">
Documentation copyright &copy; 1998-2007, the <a href="http://openbabel.org/wiki/THANKS">Open Babel Developers</a>.<br>
Open Babel is hosted by: <a href="http://sourceforge.net">
<img src="http://sourceforge.net/sflogo.php?group_id=40728" 
width="88" height="31" border="0" alt="SourceForge Logo"></a><br>
Generated on Thu Oct 13 2011 16:08:08 by&nbsp;<a href="http://www.doxygen.org/"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.7.5.1.
</div>

</body>
</html>