private double stretch ( AtomPair pair , IntStack stack , Point2d [ ] coords , Map < IBond , AtomPair > firstVisit ) { stackBackup . clear ( ) ; final double score = congestion . score ( ) ; double min = score ; for ( IBond bond : pair . bndAt ) { // don't stretch ring bonds if ( bond . isInRing ( ) ) continue ; if ( bfix . contains ( bond ) ) continue ; // has this bond already been tested as part of another pair AtomPair first = firstVisit . get ( bond ) ; if ( first == null ) firstVisit . put ( bond , first = pair ) ; if ( first != pair ) continue ; final IAtom beg = bond . getBegin ( ) ; final IAtom end = bond . getEnd ( ) ; final int begIdx = idxs . get ( beg ) ; final int endIdx = idxs . get ( end ) ; int begPriority = beg . getProperty ( AtomPlacer . PRIORITY ) ; int endPriority = end . getProperty ( AtomPlacer . PRIORITY ) ; Arrays . fill ( visited , false ) ; if ( begPriority < endPriority ) stack . len = visit ( visited , stack . xs , endIdx , begIdx , 0 ) ; else stack . len = visit ( visited , stack . xs , begIdx , endIdx , 0 ) ; backupCoords ( backup , stack ) ; if ( begPriority < endPriority ) stretch ( stack , end , beg , pair . attempt * STRETCH_STEP ) ; else stretch ( stack , beg , end , pair . attempt * STRETCH_STEP ) ; congestion . update ( visited , stack . xs , stack . len ) ; if ( percDiff ( score , congestion . score ( ) ) >= IMPROVEMENT_PERC_THRESHOLD && congestion . score ( ) < min ) { backupCoords ( coords , stack ) ; min = congestion . score ( ) ; stackBackup . copyFrom ( stack ) ; } restoreCoords ( stack , backup ) ; congestion . update ( visited , stack . xs , stack . len ) ; congestion . score = score ; } stack . copyFrom ( stackBackup ) ; return min ; }
Stretch all bonds in the shortest path between a pair of atoms in an attempt to resolve the overlap . The stretch that produces the minimum congestion is stored in the provided stack and coords with the congestion score returned .