Chemistry Reference
In-Depth Information
an RDBMS table by substituting another function for the read function. The
getdata(name, table) function would select data from an RDBMS table. The
following python code snippet shows one example of such a function.
def getdata(self, name, table):
_insql = "select smiles_to_symbols(cansmiles) as symbols, coords
from %s where name=''%s''" % (table, name)
_sql = "select * from symbol_coords('%s') as (symbol text, x
numeric, y numeri c, z numeric)" % (_insql)
for (_sym, _x, _y, _z) in ((self.conn).query(_sql).getresult()):
(self.symbols).append(_sym)
(self.coords).append( (_x, _y, _z) )
self.natoms = len(self.symbols)
return
This method is part of a class containing self.natoms , self.symbols ,
and self.coords . The final piece to be explained here is the plpgsql func-
tion symbol _ coords . This function, shown in the Appendix, accepts
an SQL statement that selects an array of symbols and an array of coordi-
nates. These are then returned as rows in order to “read” them as if they
were records in a file. The following command shows the first few rows
output from the symbol _ coords function called using the command
line psql function in a way similar to the getdata method above.
select * from
symbol_coords('select openbabel.smiles_to_symbols(cansmiles) as
symbols, coords from vla4.structure where name=''BMCL-1051-38''')
as (symbol text, x numeric, y numeric, z numeric);
symbol | x | y | z
--------+---------+---------+-----
O | -4.067 | 1.6258 | 0.0
C | -3.4418 | 1.1875 | 0.0
O | -3.4418 | 0.3625 | 0.0
C | -2.7273 | 1.6 | 0.0
C | -2.7273 | 2.425 | 0.0
C | -3.4418 | 2.8375 | 0.0
Once methods like these are in place, they readily replace traditional read
statements. RDBMS access methods are available for almost every pro-
gramming language, not just python as in this example. These were dis-
cussed in Chapter 5.
11.6 File Import, Export, and Conversions
The purpose of this topic is not to provide another method for intercon-
version of molecular file formats. The focus of this chapter it to provide
enough background information to allow the database designer to create
Search WWH ::




Custom Search