test_database.py :  » Development » Frowns » frowns » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Frowns 
Frowns » frowns » test » test_database.py
from bsddb3 import dbshelve
from frowns import Smiles,Smarts,Fingerprint

# ################################################################
# load database (this only needs to be done once
# you can comment this out at a later data
# ################################################################
# this is a persistent disk cache
cache = dbshelve.open("FOO.shelve")
molecules = ["CCCN", "c1ccccc1CCN", "C#C(N)CCc1ccccc1CCc1ccccc1"]

for m in molecules:
    mol = Smiles.smilin(m)
    fp = Fingerprint.generateFingerprint(mol)
    # cache the fingerprint using the canonical smiles
    # as the key and the fingerprint object as the value
    # shelves can store any picklable object!
    cache[mol.cansmiles()] = fp

cache.close()

# ##################################################################
# Iterate through database to see which molecules we need to
# do a full substructure search on
# ##################################################################
cache = dbshelve.open("FOO.shelve", 'r')

query = "CCCN" # this should reject molecule #2 above

testFP = Fingerprint.generateFingerprint(Smiles.smilin(query))

# this is how we iterate through a bsddb3 database
cursor = cache.cursor() # get a cursor
pair = cursor.first() # set it to the first key, value pair

while pair:           # pair will be None at end of iteration
    smiles, fp = pair # get the smiles and fingerprint
    if testFP in fp:
        print "need to substructure search", smiles    

    pair = cursor.next() # go to the next key, value pair

cache.close()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.