def toAdjacencyList(molecule, label='', pattern=False, removeH=False):
    """
    Convert the `molecule` object to an adjacency list. `pattern` specifies
    whether the graph object is a complete molecule (if ``False``) or a
    substructure pattern (if ``True``). The `label` parameter is an optional
    string to put as the first line of the adjacency list; if set to the empty
    string, this line will be omitted. If `removeH` is ``True``, hydrogen atoms
    (that do not have labels) will not be printed; this is a valid shorthand,
    as they can usually be inferred as long as the free electron numbers are
    accurate.
    """

    adjlist = ''

    if label != '': adjlist += label + '\n'

    molecule.updateConnectivityValues() # so we can sort by them
    atoms = molecule.atoms
    bonds = molecule.bonds

    for i, atom in enumerate(atoms):
        if removeH and atom.isHydrogen() and atom.label=='': continue

        # Atom number
        adjlist += '%-2d ' % (i+1)

        # Atom label
        adjlist += "%-2s " % (atom.label)

        if pattern:
            # Atom type(s)
            if len(atom.atomType) == 1:
                adjlist += atom.atomType[0].label + ' '
            else:
                adjlist += '{%s} ' % (','.join([a.label for a in atom.atomType]))
            # Electron state(s)
            if len(atom.radicalElectrons) > 1: adjlist += '{'
            for radical, spin in zip(atom.radicalElectrons, atom.spinMultiplicity):
                if radical == 0: adjlist += '0'
                elif radical == 1: adjlist += '1'
                elif radical == 2 and spin == 1: adjlist += '2S'
                elif radical == 2 and spin == 3: adjlist += '2T'
                elif radical == 3: adjlist += '3'
                elif radical == 4: adjlist += '4'
                if len(atom.radicalElectrons) > 1: adjlist += ','
            if len(atom.radicalElectrons) > 1: adjlist = adjlist[0:-1] + '}'
        else:
            # Atom type
            adjlist += "%-5s " % atom.symbol
            # Electron state(s)
            if atom.radicalElectrons == 0: adjlist += '0'
            elif atom.radicalElectrons == 1: adjlist += '1'
            elif atom.radicalElectrons == 2 and atom.spinMultiplicity == 1: adjlist += '2S'
            elif atom.radicalElectrons == 2 and atom.spinMultiplicity == 3: adjlist += '2T'
            elif atom.radicalElectrons == 3: adjlist += '3'
            elif atom.radicalElectrons == 4: adjlist += '4'
        
        # Bonds list
        atoms2 = bonds[atom].keys()
        # sort them the same way as the atoms
        #atoms2.sort(key=atoms.index)

        for atom2 in atoms2:
            if removeH and atom2.isHydrogen(): continue
            bond = bonds[atom][atom2]
            adjlist += ' {' + str(atoms.index(atom2)+1) + ','

            # Bond type(s)
            if pattern:
                if len(bond.order) == 1:
                    adjlist += bond.order[0]
                else:
                    adjlist += '{%s}' % (','.join(bond.order))
            else:
                adjlist += bond.order
            adjlist += '}'

        # Each atom begins on a new line
        adjlist += '\n'

    return adjlist