vermouth/molecule.py
def merge_molecule(self, molecule):
        """
        Add the atoms and the interactions of a molecule at the end of this
        one.

        Atom and residue index of the new atoms are offset to follow the last
        atom of this molecule.

        Parameters
        ----------
        molecule: Molecule
            The molecule to merge at the end.

        Returns
        -------
        dict
            A dict mapping the node indices of the added `molecule` to their
            new indices in this molecule.
        """
        if self.force_field != molecule.force_field:
            raise ValueError(
                'Cannot merge molecules with different force fields.'
            )
        if self.nrexcl is None and not self:
            self.nrexcl = molecule.nrexcl
        if self.nrexcl != molecule.nrexcl:
            raise ValueError(
                'Cannot merge molecules with different nrexcl. '
                'This molecule has nrexcl={}, while the other has nrexcl={}.'
                .format(self.nrexcl, molecule.nrexcl)
            )
        if self.nodes():
            # We assume that the last id is always the largest.
            last_node_idx = max(self)
            offset = last_node_idx
            residue_offset = self.nodes[last_node_idx]['resid']
            offset_charge_group = self.nodes[last_node_idx].get('charge_group', 1)
        else:
            offset = 0
            residue_offset = 0
            offset_charge_group = 0
        correspondence = {}
        for idx, node in enumerate(molecule.nodes(), start=offset + 1):
            correspondence[node] = idx
            new_atom = copy.copy(molecule.nodes[node])
            new_atom['resid'] = (new_atom.get('resid', 1) + residue_offset)
            new_atom['charge_group'] = (new_atom.get('charge_group', 1)
                                        + offset_charge_group)
            self.add_node(idx, **new_atom)
        for name, interactions in molecule.interactions.items():
            for interaction in interactions:
                atoms = tuple(correspondence[atom] for atom in interaction.atoms)
                self.add_interaction(name, atoms, interaction.parameters, interaction.meta)
        for node1, node2 in molecule.edges:
            if correspondence[node1] != correspondence[node2]:
                self.add_edge(correspondence[node1], correspondence[node2])
        return correspondence

        Add the atoms and the interactions of a molecule at the end of this
        one.

        Atom and residue index of the new atoms are offset to follow the last
        atom of this molecule.

        Parameters
        ----------
        molecule: Molecule
            The molecule to merge at the end.

        Returns
        -------
        dict
            A dict mapping the node indices of the added `molecule` to their
            new indices in this molecule.
        
Add the atoms and the interactions of a molecule at the end of this
one.

Atom and residue index of the new atoms are offset to follow the last
atom of this molecule.

Parameters

Molecule
The molecule to merge at the end.

Returns

dict
A dict mapping the node indices of the added `molecule` to their
new indices in this molecule.
Add the atoms and the interactions of a molecule at the end of this one . Atom and residue index of the new atoms are offset to follow the last atom of this molecule . Parameters Molecule The molecule to merge at the end . Returns dict A dict mapping the node indices of the added ` molecule ` to their new indices in this molecule .
def merge_molecule(self, molecule):
        if self.force_field != molecule.force_field:
            raise ValueError(
                'Cannot merge molecules with different force fields.'
            )
        if self.nrexcl is None and not self:
            self.nrexcl = molecule.nrexcl
        if self.nrexcl != molecule.nrexcl:
            raise ValueError(
                'Cannot merge molecules with different nrexcl. '
                'This molecule has nrexcl={}, while the other has nrexcl={}.'
                .format(self.nrexcl, molecule.nrexcl)
            )
        if self.nodes():
            last_node_idx = max(self)
            offset = last_node_idx
            residue_offset = self.nodes[last_node_idx]['resid']
            offset_charge_group = self.nodes[last_node_idx].get('charge_group', 1)
        else:
            offset = 0
            residue_offset = 0
            offset_charge_group = 0
        correspondence = {}
        for idx, node in enumerate(molecule.nodes(), start=offset + 1):
            correspondence[node] = idx
            new_atom = copy.copy(molecule.nodes[node])
            new_atom['resid'] = (new_atom.get('resid', 1) + residue_offset)
            new_atom['charge_group'] = (new_atom.get('charge_group', 1)
                                        + offset_charge_group)
            self.add_node(idx, **new_atom)
        for name, interactions in molecule.interactions.items():
            for interaction in interactions:
                atoms = tuple(correspondence[atom] for atom in interaction.atoms)
                self.add_interaction(name, atoms, interaction.parameters, interaction.meta)
        for node1, node2 in molecule.edges:
            if correspondence[node1] != correspondence[node2]:
                self.add_edge(correspondence[node1], correspondence[node2])
        return correspondence
def merge_molecule ( self , molecule ) : if self . force_field != molecule . force_field : raise ValueError ( 'Cannot merge molecules with different force fields.' ) if self . nrexcl is None and not self : self . nrexcl = molecule . nrexcl if self . nrexcl != molecule . nrexcl : raise ValueError ( 'Cannot merge molecules with different nrexcl. ' 'This molecule has nrexcl={}, while the other has nrexcl={}.' . format ( self . nrexcl , molecule . nrexcl ) ) if self . nodes ( ) : last_node_idx = max ( self ) offset = last_node_idx residue_offset = self . nodes [ last_node_idx ] [ 'resid' ] offset_charge_group = self . nodes [ last_node_idx ] . get ( 'charge_group' , 1 ) else : offset = 0 residue_offset = 0 offset_charge_group = 0 correspondence = { } for idx , node in enumerate ( molecule . nodes ( ) , start = offset + 1 ) : correspondence [ node ] = idx new_atom = copy . copy ( molecule . nodes [ node ] ) new_atom [ 'resid' ] = ( new_atom . get ( 'resid' , 1 ) + residue_offset ) new_atom [ 'charge_group' ] = ( new_atom . get ( 'charge_group' , 1 ) + offset_charge_group ) self . add_node ( idx , ** new_atom ) for name , interactions in molecule . interactions . items ( ) : for interaction in interactions : atoms = tuple ( correspondence [ atom ] for atom in interaction . atoms ) self . add_interaction ( name , atoms , interaction . parameters , interaction . meta ) for node1 , node2 in molecule . edges : if correspondence [ node1 ] != correspondence [ node2 ] : self . add_edge ( correspondence [ node1 ] , correspondence [ node2 ] ) return correspondence
Add the atoms and the interactions of a molecule at the end of this
one.
Add the atoms and the interactions of a molecule at the end of this one .
"""
        Add the atoms and the interactions of a molecule at the end of this
        one.

        Atom and residue index of the new atoms are offset to follow the last
        atom of this molecule.

        Parameters
        ----------
        molecule: Molecule
            The molecule to merge at the end.

        Returns
        -------
        dict
            A dict mapping the node indices of the added `molecule` to their
            new indices in this molecule.
        """ # We assume that the last id is always the largest.
self
molecule