private get valenceWithoutHydrogen()

in packages/ketcher-core/src/domain/entities/CoreAtom.ts [131:201]


  private get valenceWithoutHydrogen() {
    const charge = this.properties.charge || 0;
    const label = this.label;
    const element = Elements.get(this.label);
    // if (!element) {
    //   // query atom, skip
    //   this.implicitH = 0;
    //   return 0;
    // }

    const elementGroupNumber = element?.group;
    const radicalAmount = this.radicalAmount;
    const connectionAmount = this.calculateConnections();
    const absoluteCharge = Math.abs(charge);

    if (elementGroupNumber === 3) {
      if (
        label === AtomLabel.B ||
        label === AtomLabel.Al ||
        label === AtomLabel.Ga ||
        label === AtomLabel.In
      ) {
        if (charge === -1) {
          if (radicalAmount + connectionAmount <= 4) {
            return radicalAmount + connectionAmount;
          }
        }
      }
    } else if (elementGroupNumber === 5) {
      if (label === AtomLabel.N || label === AtomLabel.P) {
        if (charge === 1 || charge === 2) {
          return radicalAmount + connectionAmount;
        }
      } else if (
        label === AtomLabel.Sb ||
        label === AtomLabel.Bi ||
        label === AtomLabel.As
      ) {
        if (charge === 1 || charge === 2) {
          return radicalAmount + connectionAmount;
        }
      }
    } else if (elementGroupNumber === 6) {
      if (label === AtomLabel.O) {
        if (charge >= 1) {
          return radicalAmount + connectionAmount;
        }
      } else if (
        label === AtomLabel.S ||
        label === AtomLabel.Se ||
        label === AtomLabel.Po
      ) {
        if (charge === 1) {
          return radicalAmount + connectionAmount;
        }
      }
    } else if (elementGroupNumber === 7) {
      if (
        label === AtomLabel.Cl ||
        label === AtomLabel.Br ||
        label === AtomLabel.I ||
        label === AtomLabel.At
      ) {
        if (charge === 1) {
          return radicalAmount + connectionAmount;
        }
      }
    }

    return radicalAmount + connectionAmount + absoluteCharge;
  }