public static long [ ] getMorganNumbers ( IAtomContainer molecule ) { int order = molecule . getAtomCount ( ) ; long [ ] currentInvariants = new long [ order ] ; long [ ] previousInvariants = new long [ order ] ; int [ ] [ ] graph = new int [ order ] [ INITIAL_DEGREE ] ; int [ ] degree = new int [ order ] ; // which atoms are the non-hydrogens. int [ ] nonHydrogens = new int [ order ] ; for ( int v = 0 ; v < order ; v ++ ) nonHydrogens [ v ] = " H " . equals ( molecule . getAtom ( v ) . getSymbol ( ) ) ? 0 : 1 ; // build the graph and initialise the current connectivity // value to the number of connected non-hydrogens for ( IBond bond : molecule . bonds ( ) ) { int u = molecule . indexOf ( bond . getBegin ( ) ) ; int v = molecule . indexOf ( bond . getEnd ( ) ) ; graph [ u ] = Ints . ensureCapacity ( graph [ u ] , degree [ u ] + 1 , INITIAL_DEGREE ) ; graph [ v ] = Ints . ensureCapacity ( graph [ v ] , degree [ v ] + 1 , INITIAL_DEGREE ) ; graph [ u ] [ degree [ u ] ++ ] = v ; graph [ v ] [ degree [ v ] ++ ] = u ; currentInvariants [ u ] += nonHydrogens [ v ] ; currentInvariants [ v ] += nonHydrogens [ u ] ; } // iteratively sum the connectivity values for each vertex for ( int i = 0 ; i < order ; i ++ ) { System . arraycopy ( currentInvariants , 0 , previousInvariants , 0 , order ) ; for ( int u = 0 ; u < order ; u ++ ) { currentInvariants [ u ] = 0 ; // for each of the vertices adjacent to 'u' sum their // previous connectivity value int [ ] neighbors = graph [ u ] ; for ( int j = 0 ; j < degree [ u ] ; j ++ ) { int v = neighbors [ j ] ; currentInvariants [ u ] += previousInvariants [ v ] * nonHydrogens [ v ] ; } } } return currentInvariants ; }
Makes an array containing the morgan numbers of the atoms of atomContainer . These number are the extended connectivity values and not the lexicographic smallest labelling on the graph .