def preferred_mmol(code):
    """ Get mmol number of preferred biological assembly as listed in the PDBe.

    Notes
    -----
    First checks for code in mmols.json.
    If code not yet in this json dictionary, uses requests module to scrape the PDBE for the preferred mmol number.

    Parameters
    ----------
    code : str
        A PDB code.

    Returns
    -------
    mmol : int
        mmol number of preferred assembly.

    Raises
    ------
    TypeError
        If 'mmol number' scraped is not an integer.
    """
    # If preferred mmol number is already known, return it
    if code in mmols_numbers.keys():
        mmol = mmols_numbers[code][1]
        return mmol
    elif is_obsolete(code):
        raise ValueError('Obsolete PDB code {0}'.format(code))
    # Otherwise, use requests to scrape the PDBE.
    else:
        url_string = "http://www.ebi.ac.uk/pdbe/entry/pdb/{0}/analysis".format(code)
        r = requests.get(url_string)
        if not r.ok:
            raise IOError("Could not get to url {0}".format(url_string))
        r_content = r.text
        ass = re.findall('Assembly\s\d+\s\(preferred\)', r_content)
        if len(ass) != 1:
            # To catch a strange error in the pdbe where preferred assembly is not numbered. See for example
            # http://www.ebi.ac.uk/pdbe/entry/pdb/7msi/analysis
            ass = re.findall('Assembly\s+\(preferred\)', r_content)
            if len(ass) == 1:
                return 1
            obs = re.findall('Entry has been obsoleted and replaced by another entry \(OBS\)', r_content)
            if len(obs) == 1:
                rep = re.findall('by entry <a href="/pdbe/entry/pdb/\w{4}', r_content)
                if len(rep) == 1:
                    rep = rep[0][-4:]
                    raise IOError("{0} is obsolete and has been replaced by {1}.".format(code, rep))
            raise ValueError("More than one match to preferred assembly")
        mmol = ass[0].split()[1]
        try:
            mmol = int(mmol)
        except TypeError:
            raise TypeError("Unexpected match: non-integer mmol")
        return mmol
def preferred_mmol ( code ) : if code in mmols_numbers . keys ( ) : mmol = mmols_numbers [ code ] [ 1 ] return mmol elif is_obsolete ( code ) : raise ValueError ( 'Obsolete PDB code {0}' . format ( code ) ) else : url_string = "http://www.ebi.ac.uk/pdbe/entry/pdb/{0}/analysis" . format ( code ) r = requests . get ( url_string ) if not r . ok : raise IOError ( "Could not get to url {0}" . format ( url_string ) ) r_content = r . text ass = re . findall ( 'Assembly\s\d+\s\(preferred\)' , r_content ) if len ( ass ) != 1 : ass = re . findall ( 'Assembly\s+\(preferred\)' , r_content ) if len ( ass ) == 1 : return 1 obs = re . findall ( 'Entry has been obsoleted and replaced by another entry \(OBS\)' , r_content ) if len ( obs ) == 1 : rep = re . findall ( 'by entry <a href="/pdbe/entry/pdb/\w{4}' , r_content ) if len ( rep ) == 1 : rep = rep [ 0 ] [ - 4 : ] raise IOError ( "{0} is obsolete and has been replaced by {1}." . format ( code , rep ) ) raise ValueError ( "More than one match to preferred assembly" ) mmol = ass [ 0 ] . split ( ) [ 1 ] try : mmol = int ( mmol ) except TypeError : raise TypeError ( "Unexpected match: non-integer mmol" ) return mmol
Get mmol number of preferred biological assembly as listed in the PDBe.

    Notes
    -----
    First checks for code in mmols.json.
    If code not yet in this json dictionary, uses requests module to scrape the PDBE for the preferred mmol number.

    Parameters
    ----------
    code : str
        A PDB code.

    Returns
    -------
    mmol : int
        mmol number of preferred assembly.

    Raises
    ------
    TypeError
        If 'mmol number' scraped is not an integer.