void primaryCharges(IAtomContainer mol, int[][] adjList, GraphUtil.EdgeToBondMap edgeMap) {


        for (int v = 0; v < mol.getAtomCount(); v++) {
            IAtom atom = mol.getAtom(v);
            String symbType = atom.getAtomTypeName();
            BigDecimal fc = mmffParamSet.getFormalCharge(symbType);
            
            atom.setCharge(0d);

            if (fc != null) {
                atom.setCharge(fc.doubleValue());
            }
            // charge sharing between equivalent terminal oxygens
            else if (symbType.equals("O2S") || symbType.equals("O3S") || symbType.equals("O2P") || symbType.equals("O3P") || symbType.equals("O4P")) {

                // already handled
                if (atom.getCharge() != 0)
                    continue;

                // find the central atom (S or P)
                int focus = -1;
                for (int w : adjList[v]) {
                    int elem = mol.getAtom(w).getAtomicNumber();
                    if (elem == Elements.Sulfur.number() || elem == Elements.Phosphorus.number()) {
                        if (focus >= 0) {
                            focus = -2;
                            break;
                        }
                        focus = w;
                    }
                }

                // log - multiple or unfound focus
                if (focus < 0)
                    continue;

                // ensure [P+]-[O-] vs P=O are same by including the charge from
                // the focus
                double qSum = fCharge(mol.getAtom(focus));
                int nTerm = 0;

                for (int w : adjList[focus]) {
                    if (mol.getAtom(w).getAtomTypeName().equals(symbType)) {
                        qSum += fCharge(mol.getAtom(w));
                        nTerm++;
                    }
                }
                double qSplt = qSum / nTerm;

                for (int w : adjList[focus]) {
                    if (mol.getAtom(w).getAtomTypeName().equals(symbType)) {
                        atom.setCharge(qSplt);
                    }
                }

            }
            // charge sharing between nitrogen anions 
            else if (symbType.equals("N5M")) {

                if (atom.getCharge() != 0)
                    continue;

                Set<IAtom> eqiv = new HashSet<>();
                Set<Integer> visit = new HashSet<>();
                Deque<Integer> queue = new ArrayDeque<>();

                queue.add(v);

                while (!queue.isEmpty()) {
                    int w = queue.poll();
                    visit.add(w);

                    if (mol.getAtom(w).getAtomTypeName().equals("N5M"))
                        eqiv.add(mol.getAtom(w));

                    for (int u : adjList[w]) {
                        IBond bond = edgeMap.get(w, u);
                        if (bond.getProperty(MMFF_AROM) != null && !visit.contains(u)) {
                            queue.add(u);
                        }
                    }
                }

                double q = 0;
                for (IAtom eqivAtom : eqiv) {
                    q += fCharge(eqivAtom);
                }
                q /= eqiv.size();
                for (IAtom eqivAtom : eqiv) {
                    eqivAtom.setCharge(q);
                }
            }
        }
    }
void primaryCharges ( IAtomContainer mol , int [ ] [ ] adjList , GraphUtil . EdgeToBondMap edgeMap ) { for ( int v = 0 ; v < mol . getAtomCount ( ) ; v ++ ) { IAtom atom = mol . getAtom ( v ) ; String symbType = atom . getAtomTypeName ( ) ; BigDecimal fc = mmffParamSet . getFormalCharge ( symbType ) ; atom . setCharge ( 0d ) ; if ( fc != null ) { atom . setCharge ( fc . doubleValue ( ) ) ; } else if ( symbType . equals ( "O2S" ) || symbType . equals ( "O3S" ) || symbType . equals ( "O2P" ) || symbType . equals ( "O3P" ) || symbType . equals ( "O4P" ) ) { if ( atom . getCharge ( ) != 0 ) continue ; int focus = - 1 ; for ( int w : adjList [ v ] ) { int elem = mol . getAtom ( w ) . getAtomicNumber ( ) ; if ( elem == Elements . Sulfur . number ( ) || elem == Elements . Phosphorus . number ( ) ) { if ( focus >= 0 ) { focus = - 2 ; break ; } focus = w ; } } if ( focus < 0 ) continue ; double qSum = fCharge ( mol . getAtom ( focus ) ) ; int nTerm = 0 ; for ( int w : adjList [ focus ] ) { if ( mol . getAtom ( w ) . getAtomTypeName ( ) . equals ( symbType ) ) { qSum += fCharge ( mol . getAtom ( w ) ) ; nTerm ++ ; } } double qSplt = qSum / nTerm ; for ( int w : adjList [ focus ] ) { if ( mol . getAtom ( w ) . getAtomTypeName ( ) . equals ( symbType ) ) { atom . setCharge ( qSplt ) ; } } } else if ( symbType . equals ( "N5M" ) ) { if ( atom . getCharge ( ) != 0 ) continue ; Set < IAtom > eqiv = new HashSet < > ( ) ; Set < Integer > visit = new HashSet < > ( ) ; Deque < Integer > queue = new ArrayDeque < > ( ) ; queue . add ( v ) ; while ( ! queue . isEmpty ( ) ) { int w = queue . poll ( ) ; visit . add ( w ) ; if ( mol . getAtom ( w ) . getAtomTypeName ( ) . equals ( "N5M" ) ) eqiv . add ( mol . getAtom ( w ) ) ; for ( int u : adjList [ w ] ) { IBond bond = edgeMap . get ( w , u ) ; if ( bond . getProperty ( MMFF_AROM ) != null && ! visit . contains ( u ) ) { queue . add ( u ) ; } } } double q = 0 ; for ( IAtom eqivAtom : eqiv ) { q += fCharge ( eqivAtom ) ; } q /= eqiv . size ( ) ; for ( IAtom eqivAtom : eqiv ) { eqivAtom . setCharge ( q ) ; } } } }
Internal method, MMFF primary charges. Tabulated (MMFFFORMCHG.PAR) and
variable (assigned in code).

@param mol molecule
@param adjList adjacency list representation
@param edgeMap edge to bond mapping