pub fn add_bond(&mut self, mut particle_i: usize, mut particle_j: usize) -> Vec<Permutation> {
        assert!(particle_i <= self.particles.len());
        assert!(particle_j <= self.particles.len());
        assert_ne!(particle_i, particle_j);
        trace!(
            "Adding bond {}-{} between molecules {} and {}",
            particle_i,
            particle_j,
            self.molecule_ids[particle_i],
            self.molecule_ids[particle_j]
        );

        // Getting copy of the molecules before the merge
        let molid_i = self.molecule_ids[particle_i];
        let molid_j = self.molecule_ids[particle_j];
        let new_molid = min(molid_i, molid_j);
        let old_molid = max(molid_i, molid_j);
        let new_mol = self.bondings[new_molid].clone();
        let old_mol = self.bondings[old_molid].clone();
        let already_in_same_molecule = self.are_in_same_molecule(particle_i, particle_j);

        // Effective merge
        let delta = self.merge_molecules(molid_i, molid_j);

        let mut permutations = Vec::new();
        // If new_mol.last() + 1 == old_mol.first(), no one moved. Else,
        // we generate the permutations
        if !already_in_same_molecule && new_mol.end() != old_mol.start() {
            let size = old_mol.size();
            let first = old_mol.start();
            let second = new_mol.end();
            // Add permutation for the molecule we just moved around
            for i in 0..size {
                permutations.push(Permutation::new(first + i, second + i));
            }

            // Add permutations for molecules that where shifted to make
            // space for the just moved molecule.
            for connectivity in &self.bondings[new_molid + 1..old_molid] {
                for i in connectivity.indexes() {
                    permutations.push(Permutation::new(i - size, i));
                }
            }
        }

        // One of the `particle_i` or `particle_j` index is no longer valid, as
        // one molecule has been displaced.
        if molid_i == new_molid {
            particle_j -= delta; // j moved
        } else {
            particle_i -= delta; // i moved
        };

        assert_eq!(self.molecule_ids[particle_i], self.molecule_ids[particle_j]);
        self.bondings[self.molecule_ids[particle_i]].add_bond(particle_i, particle_j);
        return permutations;
    }
/// Add a bond between the particles at indexes `i` and `j`. The particles
/// should have been added to the configuration before calling this.
///
/// # Warning
///
/// If the bond is between two particles which are not in the same molecule,
/// the two molecules are merged together by moving particles in the
/// particles list, and thus invalidate any previously stored index. In
/// particular, any bond, angle, dihedral or molecule is invalidated.
///
/// This function will return the list of atomic permutations that where
/// applied in order to ensure that molecules are contiguous in memory.
Add a bond between the particles at indexes `i` and `j`. The particles
should have been added to the configuration before calling this.
Add a bond between the particles at indexes ` i ` and ` j ` . The particles should have been added to the configuration before calling this .
pub fn add_bond(&mut self, mut particle_i: usize, mut particle_j: usize) -> Vec<Permutation> {
        assert!(particle_i <= self.particles.len());
        assert!(particle_j <= self.particles.len());
        assert_ne!(particle_i, particle_j);
        trace!(
            "Adding bond {}-{} between molecules {} and {}",
            particle_i,
            particle_j,
            self.molecule_ids[particle_i],
            self.molecule_ids[particle_j]
        );
        // Getting copy of the molecules before the merge
        let molid_i = self.molecule_ids[particle_i];
        let molid_j = self.molecule_ids[particle_j];
        let new_molid = min(molid_i, molid_j);
        let old_molid = max(molid_i, molid_j);
        let new_mol = self.bondings[new_molid].clone();
        let old_mol = self.bondings[old_molid].clone();
        let already_in_same_molecule = self.are_in_same_molecule(particle_i, particle_j);
        // Effective merge
        let delta = self.merge_molecules(molid_i, molid_j);
        let mut permutations = Vec::new();
        // If new_mol.last() + 1 == old_mol.first(), no one moved. Else,
        // we generate the permutations
        if !already_in_same_molecule && new_mol.end() != old_mol.start() {
            let size = old_mol.size();
            let first = old_mol.start();
            let second = new_mol.end();
            // Add permutation for the molecule we just moved around
            for i in 0..size {
                permutations.push(Permutation::new(first + i, second + i));
            }
            // Add permutations for molecules that where shifted to make
            // space for the just moved molecule.
            for connectivity in &self.bondings[new_molid + 1..old_molid] {
                for i in connectivity.indexes() {
                    permutations.push(Permutation::new(i - size, i));
                }
            }
        }
        // One of the `particle_i` or `particle_j` index is no longer valid, as
        // one molecule has been displaced.
        if molid_i == new_molid {
            particle_j -= delta; // j moved
        } else {
            particle_i -= delta; // i moved
        };
        assert_eq!(self.molecule_ids[particle_i], self.molecule_ids[particle_j]);
        self.bondings[self.molecule_ids[particle_i]].add_bond(particle_i, particle_j);
        return permutations;
    }
pub fn add_bond ( & mut self , mut particle_i : usize , mut particle_j : usize ) -> Vec < Permutation > { assert ! ( particle_i self particles len ( ) ) ; assert ! ( particle_j self particles len ( ) ) ; assert_ne ! ( particle_i particle_j ) ; trace ! ( " " particle_i particle_j self molecule_ids [ particle_i ] self molecule_ids [ particle_j ] ) ; // Getting copy of the molecules before the merge let molid_i = self . molecule_ids [ particle_i ] ; let molid_j = self . molecule_ids [ particle_j ] ; let new_molid = min ( molid_i , molid_j ) ; let old_molid = max ( molid_i , molid_j ) ; let new_mol = self . bondings [ new_molid ] . clone ( ) ; let old_mol = self . bondings [ old_molid ] . clone ( ) ; let already_in_same_molecule = self . are_in_same_molecule ( particle_i , particle_j ) ; // Effective merge let delta = self . merge_molecules ( molid_i , molid_j ) ; let mut permutations = Vec :: new ( ) ; // If new_mol.last() + 1 == old_mol.first(), no one moved. Else, // we generate the permutations if ! already_in_same_molecule && new_mol . end ( ) != old_mol . start ( ) { let size = old_mol . size ( ) ; let first = old_mol . start ( ) ; let second = new_mol . end ( ) ; // Add permutation for the molecule we just moved around for i in 0 .. size { permutations . push ( Permutation :: new ( first + i , second + i ) ) ; } // Add permutations for molecules that where shifted to make // space for the just moved molecule. for connectivity in & self . bondings [ new_molid + 1 .. old_molid ] { for i in connectivity . indexes ( ) { permutations . push ( Permutation :: new ( i - size , i ) ) ; } } } // One of the `particle_i` or `particle_j` index is no longer valid, as // one molecule has been displaced. if molid_i == new_molid { particle_j -= delta ; // j moved } else { particle_i -= delta ; // i moved } ; assert_eq ! ( self molecule_ids [ particle_i ] self molecule_ids [ particle_j ] ) ; self . bondings [ self . molecule_ids [ particle_i ] ] . add_bond ( particle_i , particle_j ) ; return permutations ; }
Add a bond between the particles at indexes `i` and `j`.
Add a bond between the particles at indexes ` i ` and ` j ` .
&mut self
particle_i
usize
particle_j
usize
warning
If the bond is between two particles which are not in the same molecule,
the two molecules are merged together by moving particles in the
particles list, and thus invalidate any previously stored index. In
particular, any bond, angle, dihedral or molecule is invalidated.

This function will return the list of atomic permutations that where
applied in order to ensure that molecules are contiguous in memory.
If the bond is between two particles which are not in the same molecule the two molecules are merged together by moving particles in the particles list and thus invalidate any previously stored index . In particular any bond angle dihedral or molecule is invalidated . This function will return the list of atomic permutations that where applied in order to ensure that molecules are contiguous in memory .