Back to index

python-biopython  1.60
Public Member Functions | Static Public Attributes | Private Member Functions
Bio.PDB.MMCIF2Dict.MMCIF2Dict Class Reference

List of all members.

Public Member Functions

def __init__

Static Public Attributes

int NAME = 1
int LOOP = 2
int DATA = 3
int SEMICOLONS = 4
int DOUBLEQUOTED = 5
int QUOTED = 6
int SIMPLE = 7

Private Member Functions

def _make_mmcif_dict

Detailed Description

Definition at line 13 of file MMCIF2Dict.py.


Constructor & Destructor Documentation

def Bio.PDB.MMCIF2Dict.MMCIF2Dict.__init__ (   self,
  filename 
)

Definition at line 23 of file MMCIF2Dict.py.

00023 
00024     def __init__(self, filename):
00025         if not os.path.isfile(filename):
00026             raise IOError("File not found.")
00027         MMCIFlex.open_file(filename)
00028         dict.__init__(self, **self._make_mmcif_dict())
00029         MMCIFlex.close_file()

Here is the call graph for this function:


Member Function Documentation

Loop through PLY token (type, value) pairs, return a dict.

Definition at line 30 of file MMCIF2Dict.py.

00030 
00031     def _make_mmcif_dict(self): 
00032         """
00033         Loop through PLY token (type, value) pairs, return a dict.
00034 
00035         """
00036         # this dict will contain the name/data pairs 
00037         mmcif_dict = {}
00038         # entry for garbage
00039         mmcif_dict[None] = []
00040         # local copies
00041         NAME=self.NAME
00042         LOOP=self.LOOP
00043         DATA=self.DATA
00044         SEMICOLONS=self.SEMICOLONS
00045         DOUBLEQUOTED=self.DOUBLEQUOTED
00046         QUOTED=self.QUOTED
00047         SIMPLE=self.SIMPLE
00048         get_token=MMCIFlex.get_token
00049         # are we looping?
00050         loop_flag=0
00051         # list of names in loop
00052         temp_list=[]
00053         # last encountered name
00054         current_name=None
00055         # get first token/value pair
00056         token, value=get_token()
00057         # print token, value
00058         # loop until EOF (token==0)
00059         while token:
00060             if token==NAME:
00061                 if loop_flag:
00062                     # Make lists for all the names in the loop
00063                     while token==NAME:
00064                         # create  a list for each name encountered in loop
00065                         new_list=mmcif_dict[value]=[]
00066                         temp_list.append(new_list)
00067                         token, value=get_token()  
00068                         # print token, value
00069                     loop_flag=0         
00070                     # nr of data items parsed
00071                     data_counter=0
00072                     # corresponding data name
00073                     pos=0
00074                     nr_fields=len(temp_list)
00075                     # Now fill all lists with the data
00076                     while token>3:
00077                         pos=data_counter%nr_fields
00078                         data_counter=data_counter+1
00079                         temp_list[pos].append(value)
00080                         token, value=get_token()  
00081                         # print token, value
00082                     if pos!=nr_fields-1:
00083                         warnings.warn("ERROR: broken name-data pair "
00084                                       "(data missing)!", RuntimeWarning)
00085                     # The last token was not used, so
00086                     # don't set token to None! (this means the 
00087                     # last parsed token goes through the loop again)
00088                 else:   
00089                     # simple name-data pair (no loop)
00090                     # so next token should be the data
00091                     next_token, data=get_token()  
00092                     # print token, value
00093                     mmcif_dict[value]=data
00094                     if next_token<4:
00095                         warnings.warn("ERROR: broken name-data pair "
00096                                       "(name-non data pair)!", RuntimeWarning)
00097                         # print token, value
00098                     else:   
00099                         # get next token
00100                         token=None
00101             elif token==LOOP:
00102                 loop_flag=1
00103                 temp_list=[]
00104                 # get next token
00105                 token=None
00106             elif token==DATA:
00107                 mmcif_dict[value[0:5]]=value[5:]
00108                 token=None
00109             else:
00110                 # we found some complete garbage
00111                 warnings.warn("ERROR: broken name-data pair "
00112                               "(missing name)!\n%s %s" % (token, value),
00113                               RuntimeWarning)
00114                 mmcif_dict[None].append(value)
00115                 # get next token
00116                 token=None
00117             if token==None:
00118                 token, value=get_token()
00119                 # print token, value
00120         return mmcif_dict
00121 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 17 of file MMCIF2Dict.py.

Definition at line 19 of file MMCIF2Dict.py.

Definition at line 16 of file MMCIF2Dict.py.

Definition at line 15 of file MMCIF2Dict.py.

Definition at line 20 of file MMCIF2Dict.py.

Definition at line 18 of file MMCIF2Dict.py.

Definition at line 21 of file MMCIF2Dict.py.


The documentation for this class was generated from the following file: