Beispiel #1
0
    def getPDBAtomName(self, name, element):
        """Figure out the real atom name as well as the atom element, if name
        string is in pdb format"""
        # To be DONE
##          bad = 0
##          for c in element:
##              if c not in string.letters: bad = 1
        if element == '  ' or element == '':# or bad:
##              if name[0] != ' ':
##                  element = string.strip(name[0:1])
##                  # Won't work if the atomType is FE !!!!
##              else:
            element = string.strip(name[0:2])
        else:
            element = string.strip(element)
            # should I still check that it really is an element ???
        if name[1]=='H':
            if name[0] in ('1','2','3'):
                name = string.strip(name[1:])+name[0]
                element = 'H'
        if len(element)==2:
            element = element[0]+string.lower(element[1])
        elem = string.lower(element)
        if elem =='lp' or elem =='ld':
            element = 'Xx'
        return string.strip(name), element
 def clean_atom_type(self, type_name):
     name = string.upper(type_name[0])
     if len(type_name) > 1:
         name = name + string.lower(type_name[1])
         if name[1] not in string.letters:
             return name[0]
     return name
 def get_atomic_number(self, name):
     """return the element number for a given name or raises a
     ValueError exception if the element is not known"""
     _name = string.upper(name[0])
     if len(name) > 1:
         if not name[1] in string.digits:
             _name = _name + string.lower(name[1])
     if _name in list(babel_elements.keys()):
         return babel_elements[_name]['num']
     else:
         raise ValueError( "Could not find atomic number for %s %s"% \
                           (name,_name) )
    def get_Attr(self, html, pattern, lc=0):
        attrPat = re.compile(
            ('([%s]*=[%s]*' % (string.whitespace, string.whitespace)) +
            r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./:+*%?!\(\)_#=~]*))?')

        found = pattern.search(html)
        if found:
            attrP = attrPat.search(html[found.end():])
            if attrP:
                attr = attrP.group()[1:]
                if attr and attr[0] == '"' and attr[-1] == '"':
                    if len(attr) > 2:
                        attr = attr[1:-1]
                if lc:
                    return string.lower(attr)
                else:
                    return attr
        else:
            return None
    def __init__(self,
                 url=None,
                 name=None,
                 method=None,
                 action=None,
                 enctype=None,
                 input=None,
                 radiobutton=None,
                 checkbutton=None,
                 select=None,
                 textarea=None,
                 arguments=None,
                 hiddenInput=None,
                 fieldOrder=None):

        # note: something i don't understand: in the constructor, i cannot say
        # radiobutton={} and then self.radiobutton = radiobutton
        # because every new instance of this class would point to the
        # dictionary of the first instance (tested with python1.5 to 2.2).
        # Instead, i have to initialise radiobutton=None and do the test below

        self.url = url  # url: e.g. 'http://www.google.com'
        self.name = name  # name of this form object

        if method is None: method = 'get'
        assert string.lower(method) in ['post', 'get']
        self.method = method  # default cgi method, if not specified

        self.action = action  # the cgi action. In case of google: '/search'
        self.enctype = enctype  # enctype of CGI Form

        if input is None: input = {}
        self.input = input  # dictionary with all the 'inputs' of this form
        # note that input of type 'hidden' is not added
        # to this dict, but to self.hiddenInput, input of
        # type 'radio' and 'checkbox' are added to
        # different dicts too as well as input of type
        # 'select' and 'textarea'

        if radiobutton is None: radiobutton = {}
        self.radiobutton = radiobutton  # dict holding the radiobuttons

        if checkbutton is None: checkbutton = {}
        self.checkbutton = checkbutton  # dict holding the checkbox buttons

        if select is None: select = {}
        self.select = select  # dictionary with all the 'selects' of this form

        if textarea is None: textarea = {}
        self.textarea = textarea  # dictionary with all the 'textareas'

        if arguments is None: arguments = {}
        self.arguments = arguments  # dict with the arguments that are used to
        # generate the string to be sent to the
        # server

        if hiddenInput is None: hiddenInput = {}
        self.hiddenInput = hiddenInput  # dictionary with all the inputs of
        # type 'hidden'

        if fieldOrder is None: fieldOrder = []
        self.fieldOrder = fieldOrder  # stores tuples of (inputname, dictname)