code: def _bridge_dangling_Os(self, oh_density, thickness):
          
  
          area = self.periodicity[0] * self.periodicity[1]
          target = int(oh_density * area)
  
          dangling_Os = [atom for atom in self.particles()
                         if atom.name == 'O' and
                         atom.pos[2] > thickness and
                         len(self.bond_graph.neighbors(atom)) == 1]
  
          n_bridges = int((len(dangling_Os) - target) / 2)
  
          for _ in range(n_bridges):
              bridged = False
              while not bridged:
                  O1 = random.choice(dangling_Os)
                  Si1 = self.bond_graph.neighbors(O1)[0]
                  for O2 in dangling_Os:
                      if O2 == O1:
                          continue
                      Si2 = self.bond_graph.neighbors(O2)[0]
                      if Si1 == Si2:
                          continue
                      if any(neigh in self.bond_graph.neighbors(Si2)
                             for neigh in self.bond_graph.neighbors(Si1)):
                          continue
                      r = self.min_periodic_distance(Si1.pos, Si2.pos)
                      if r < 0.45:
                          bridged = True
                          self.add_bond((O1, Si2))
                          dangling_Os.remove(O1)
                          dangling_Os.remove(O2)
                          self.remove(O2)
                          break
docs: Form Si-O-Si bridges to yield desired density of reactive surface sites.
  
          References
          ----------
          .. [1] Hartkamp, R., Siboulet, B., Dufreche, J.-F., Boasne, B.
                 "Ion-specific adsorption and electroosmosis in charged
                 amorphous porous silica." (2015) Phys. Chem. Chem. Phys.
                 17, 24683-24695