code: @Override
      public void setAtom(int idx, IAtom atom) {
          if (idx >= atomCount)
              throw new IndexOutOfBoundsException("No atom at index: " + idx);
          int aidx = indexOf(atom);
          if (aidx >= 0)
              throw new IllegalArgumentException("Atom already in container at index: " + idx);
          final IAtom oldAtom = atoms[idx];
          atoms[idx] = atom;
  
          // update electron containers
          for (IBond bond : bonds()) {
              for (int i = 0; i < bond.getAtomCount(); i++) {
                  if (oldAtom.equals(bond.getAtom(i))) {
                      bond.setAtom(atom, i);
                  }
              }
          }
          for (ISingleElectron ec : singleElectrons()) {
              if (oldAtom.equals(ec.getAtom()))
                  ec.setAtom(atom);
          }
          for (ILonePair lp : lonePairs()) {
              if (oldAtom.equals(lp.getAtom()))
                  lp.setAtom(atom);
          }
  
          // update stereo
          List<IStereoElement> oldStereo = null;
          List<IStereoElement> newStereo = null;
          for (IStereoElement se : stereoElements()) {
              if (se.contains(oldAtom)) {
                  if (oldStereo == null) {
                      oldStereo = new ArrayList<>();
                      newStereo = new ArrayList<>();
                  }
                  oldStereo.add(se);
                  Map<IAtom, IAtom> amap = Collections.singletonMap(oldAtom, atom);
                  Map<IBond, IBond> bmap = Collections.emptyMap();
                  newStereo.add(se.map(amap, bmap));
              }
          }
          if (oldStereo != null) {
              stereoElements.removeAll(oldStereo);
              stereoElements.addAll(newStereo);
          }
      }
docs: {@inheritDoc}