test_class.file: storage/ctab/src/test/java/org/openscience/cdk/io/MDLValenceTest.java
test_class.identifier: MDLValenceTest
test_case.body: @Test
      public void sodium_hydride() {
          IAtomContainer container = new AtomContainer();
          IAtom atom = new Atom("Na");
          atom.setValency(1);
          container.addAtom(atom);
          MDLValence.apply(container);
          assertThat(atom.getValency(), is(1));
          assertThat(atom.getImplicitHydrogenCount(), is(1));
      }
test_case.class_method_signature: MDLValenceTest.sodium_hydride()
test_case.full_signature: @Test public void sodium_hydride()
test_case.identifier: sodium_hydride
test_case.invocations: setValency addAtom apply assertThat getValency is assertThat getImplicitHydrogenCount is
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void sodium_hydride()
focal_class.file: storage/ctab/src/main/java/org/openscience/cdk/io/MDLValence.java
focal_class.identifier: MDLValence
focal_class.class_method_signature: MDLValence.MDLValence()
focal_class.full_signature: private  MDLValence()
focal_class.identifier: MDLValence
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.signature:  MDLValence()
focal_class.class_method_signature: MDLValence.apply(IAtomContainer container)
focal_class.full_signature: static IAtomContainer apply(IAtomContainer container)
focal_class.identifier: apply
focal_class.modifiers: static
focal_class.parameters: (IAtomContainer container)
focal_class.return: IAtomContainer
focal_class.signature: IAtomContainer apply(IAtomContainer container)
focal_class.class_method_signature: MDLValence.implicitValence(int elem, int q, int val)
focal_class.full_signature: static int implicitValence(int elem, int q, int val)
focal_class.identifier: implicitValence
focal_class.modifiers: static
focal_class.parameters: (int elem, int q, int val)
focal_class.return: int
focal_class.signature: int implicitValence(int elem, int q, int val)
focal_method.body: static IAtomContainer apply(IAtomContainer container) {
  
          int n = container.getAtomCount();
  
          int[] valences = new int[n];
  
          Map<IAtom, Integer> atomToIndex = Maps.newHashMapWithExpectedSize(n);
          for (IAtom atom : container.atoms())
              atomToIndex.put(atom, atomToIndex.size());
  
          // compute the bond order sums
          for (IBond bond : container.bonds()) {
              int u = atomToIndex.get(bond.getBegin());
              int v = atomToIndex.get(bond.getEnd());
  
              int bondOrder = bond.getOrder().numeric();
  
              valences[u] += bondOrder;
              valences[v] += bondOrder;
          }
  
          for (int i = 0; i < n; i++) {
  
              IAtom atom = container.getAtom(i);
              Integer charge = atom.getFormalCharge();
              Integer element = atom.getAtomicNumber();
  
              if (element == null) continue;
  
              // unset = 0 in this case
              charge = charge == null ? 0 : charge;
  
              int explicit = valences[i];
  
              // if there was a valence read from the mol file use that otherwise
              // use the default value from the valence model to set the correct
              // number of implied hydrogens
              if (atom.getValency() != null) {
                  atom.setImplicitHydrogenCount(atom.getValency() - explicit);
              } else {
                  int implicit = implicitValence(element, charge, valences[i]);
                  atom.setImplicitHydrogenCount(implicit - explicit);
                  atom.setValency(implicit);
              }
          }
  
          return container;
      }
focal_method.class_method_signature: MDLValence.apply(IAtomContainer container)
focal_method.full_signature: static IAtomContainer apply(IAtomContainer container)
focal_method.identifier: apply
focal_method.invocations: getAtomCount newHashMapWithExpectedSize atoms put size bonds get getBegin get getEnd numeric getOrder getAtom getFormalCharge getAtomicNumber getValency setImplicitHydrogenCount getValency implicitValence setImplicitHydrogenCount setValency
focal_method.modifiers: static
focal_method.parameters: (IAtomContainer container)
focal_method.return: IAtomContainer
focal_method.signature: IAtomContainer apply(IAtomContainer container)