test_pruneback.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_pruneback.py
from frowns import Smiles,Smarts,MDL,Fingerprint
from frowns.perception import RingDetection


def removeTerminalAtoms(m):
    while 1:
        to_remove = []
        for atom in m.atoms:
            if atom.symbol == "C" and len(atom.bonds) == 1:
                to_remove.append(atom)

        if not to_remove:
            break

        for atom in to_remove:
            m.remove_atom(atom)

    return m
            
m = Smiles.smilin("c1ccccc1CCNc1cccc1CCC")

print m.cansmiles()
removeTerminalAtoms(m)
smarts = m.arbsmarts()
print smarts

pat = Smarts.compile(smarts)
assert pat.match(m)

smiles = []

file = open("F:\\Chemical Libraries\\Libraries to Purchase\\Nat_425.sdf")

reader = MDL.mdlin(file)
mol = reader.next()

print "reading natural products"
i = 0
while mol:
    fp = Fingerprint.generateFingerprint(mol)
    smile = mol.cansmiles()
    mol = removeTerminalAtoms(mol)
    smiles.append((len(mol.atoms), len(mol.bonds), smile, mol.arbsmarts(), i, fp))
    i += 1
    mol = reader.next()

search = smiles
search.sort()

smiles = []


print "processing"

dict = {}
indicesUsed = {}

# trim the search list
final_search_list = []

while search:
    atoms, bonds, smile, smarts, index, fp = search.pop(0)
    final_search_list.append((atoms, bonds, smile, smarts, index, fp))
    
    pat = Smarts.compile(smarts)
    next = []
    key = (smarts, index)
    for atoms, bonds, smile, smarts2, index, fp2 in search:
        if smarts == smarts2:
            dict[key] = dict.get(key, []) + [(smile, index)]
        elif fp in fp2 and pat.match(Smiles.smilin(smile), 1):
            dict[key] = dict.get(key, []) + [(smile, index)]
        else:
            next.append((atoms, bonds, smile, smarts2, index, fp2))

    search = next

print "reduced search list to", len(final_search_list)

file = open("F:\\Chemical Libraries\\Libraries to Purchase\\Semi-Nat_9575.sdf")
reader = MDL.mdlin(file)
mol = reader.next()

print "reading semi-natural products"
while mol:
    fp = Fingerprint.generateFingerprint(mol)
    smile = mol.cansmiles()
    mol = removeTerminalAtoms(mol)
    smiles.append((len(mol.atoms), len(mol.bonds), smile, mol.arbsmarts(), i, fp))
    i += 1
    mol = reader.next()
    
smiles.sort()

while final_search_list:
    atoms, bonds, smile, smarts, index, fp = final_search_list.pop(0)
    
    pat = Smarts.compile(smarts)
    next = []
    key = (smarts, index)
    for atoms, bonds, smile, smarts2, index, fp2 in smiles:
        if smarts == smarts2:
            dict[key] = dict.get(key, []) + [(smile, index)]
        elif fp in fp2 and pat.match(Smiles.smilin(smile), 1):
            dict[key] = dict.get(key, []) + [(smile, index)]
        else:
            next.append((atoms, bonds, smile, smarts2, index, fp2))

    smiles = next  
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.