Bond.py :  » Development » Frowns » frowns » 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 » Bond.py
"""Bond class
Bonds """
from IdGenerator import defaultGenerator
import weakref

#DAYLIGHT CIS/TRANS support
DX_CHI_CIS=1
DX_CHI_TRANS=2
DX_CHI_NO_DBO=3

#Chirality Support
UP = "UP"
DOWN = "DOWN"
EITHER = "EITHER"

class Bond(object):
    __slots__ = ["adjunct", "atoms", "index", "rings", "_closure",
                 "dbo", "stereo", "parent", "handle",
                 "symbol", "aromatic", "bondorder", "equiv_class",
                 "bondtype", "fixed", "_traverseOrder", "_line"]
    
    def __init__(self,
                 symbol="-",
                 bondorder=1,
                 bondtype=1,
                 fixed=0,
                 stereo=None,                
                 generator=defaultGenerator):
        self.reset(symbol, bondorder, bondtype, fixed, stereo)

        self.adjunct = 0
        self.atoms = []

        self.index = -1
        self.rings = []
        self._closure = 0
        self.dbo = None
        self.stereo = None
        self.parent = None
        
        self.handle = id(self) #generator() # generate a new unique
                               #   # handle
           
    def setdbo(self, bond1, bond2, dboval):
        """Set the double bond orientation for bond1 and bond2
        based on this bond"""
        # this bond must be a double bond
        if self.bondtype != 2:
            raise FrownsError("To set double bond order, center bond must be double!")
        assert dboval in [DX_CHI_CIS, DX_CHI_TRANS, DX_CHI_NO_DBO], "bad dboval value"
        
        self.dbo.append(bond1, bond2, dboval)
        
            
    def reset(self, symbol, bondorder, bondtype, fixed, stereo):
        self.symbol = symbol
        self.bondorder = bondorder
        self.equiv_class = self.bondtype = bondtype
        self.fixed = fixed
        self.stereo = stereo
        # set the aromaticity correctly
        if self.bondtype == 4:
            self.aromatic = 1
        else:
            assert self.bondtype == self.bondorder
            self.aromatic = 0
        
    def set_symbol(self, symbol):
        """(symbol, bondorder) -> set the bondsymbol
        of the molecule"""
        raise "Deprecated"
        self.symbol, self.bondtype, bondorder, self.equiv_class = \
                     BONDLOOKUP[symbol]
        if self.bondtype == 4:
            self.aromatic = 1
        else:
            self.aromatic = 0


    def set_parent(self, parent):
        self.parent = weakref.ref(parent)

    def destroy(self):
        self.parent = None
        if self.atoms:
            a1, a2 = self.atoms
            a1.bonds.remove(self)
            a2.bonds.remove(self)
            a1.oatoms.remove(a2)
            a2.oatoms.remove(a1)
        self.rings = []
                
    def xatom(self, atom):
        """(atom)->return the atom at the other end of this bond
        or None if atom is not part of this bond"""
        handle = atom.handle
        
        if handle == self.atoms[0].handle:
            return self.atoms[1]
        elif handle == self.atoms[1].handle:
            return self.atoms[0]
        return None
        

    def __repr__(self):
        return "%s(%s)"%(self.__class__.__name__,
                         self.index)

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