Esempio n. 1
0
    def compute_element_masses(self, inplace=False):
        '''
        Map element symbols to their corresponding (element) mass.

        Args:
            inplace (bool): Add as a column (default false - return series)
        '''
        elem_mass = symbol_to_element_mass()
        mass = self['symbol'].astype('O').map(elem_mass)
        if inplace:
            self['mass'] = masses
        else:
            return masses
Esempio n. 2
0
def compute_molecule(universe):
    """
    Cluster atoms into molecules and create the :class:`~exatomic.molecule.Molecule`
    table.

    Args:
        universe: Atomic universe

    Returns:
        molecule: Molecule table

    Warning:
        This function modifies the universe's atom (:class:`~exatomic.atom.Atom`)
        table in place!
    """
    nodes = universe.atom.index.values
    bonded = universe.atom_two.ix[universe.atom_two["bond"] == True, ["atom0", "atom1"]]
    edges = zip(bonded["atom0"].astype(np.int64), bonded["atom1"].astype(np.int64))
    g = nx.Graph()
    g.add_nodes_from(nodes)
    g.add_edges_from(edges)
    # generate molecule indices for the atom table
    mapper = {}
    i = 0
    for k, v in g.degree().items():  # First handle single atom "molecules"
        if v == 0:
            mapper[k] = i
            i += 1
    for seht in connected_components(g):  # Second handle multi atom molecules
        for adx in seht:
            mapper[adx] = i
        i += 1
    universe.atom["molecule"] = universe.atom.index.map(lambda x: mapper[x])
    sym2mass = symbol_to_element_mass()
    universe.atom["mass"] = universe.atom["symbol"].map(sym2mass)
    grps = universe.atom.groupby("molecule")
    molecule = grps["symbol"].value_counts().unstack().fillna(0).astype(np.int64)
    molecule.columns.name = None
    molecule["mass"] = grps["mass"].sum()
    universe.atom["molecule"] = universe.atom["molecule"].astype("category")
    del universe.atom["mass"]
    return molecule
Esempio n. 3
0
 def get_element_masses(self):
     """Compute and return element masses from symbols."""
     elem_mass = symbol_to_element_mass()
     return self['symbol'].astype('O').map(elem_mass)