public double displace ( IAtomContainer ac , Vector overlappingAtoms , Vector overlappingBonds ) { double bondLength = GeometryUtil . getBondLengthAverage ( ac ) ; OverlapPair op = null ; IAtom a1 = null , a2 = null ; Vector2d v1 = null , v2 = null ; int steps = 0 ; int p = 0 ; double overlapScore = 0 ; double choice = 0 ; logger . debug ( "We are here because of an overlap situation." ) ; //logger.debug("Overlap score: " + overlapScore); do { /* * we take a random overlapping pair of atoms */ p = ( int ) ( Math . random ( ) * overlappingAtoms . size ( ) ) ; logger . debug ( "Taking overlap pair no. " + p ) ; op = ( OverlapPair ) overlappingAtoms . elementAt ( p ) ; /* * Now we have an overlapping pair of atoms We calculate the 2D * vector formed by the positions of both and translate one of the * atoms by one tenth of a bond length */ a1 = ( IAtom ) op . chemObject1 ; a2 = ( IAtom ) op . chemObject2 ; v1 = new Vector2d ( a1 . getPoint2d ( ) ) ; v2 = new Vector2d ( a2 . getPoint2d ( ) ) ; v2 . sub ( v1 ) ; v2 . normalize ( ) ; if ( Double . isNaN ( v2 . x ) ) v2 . x = 0.01 ; if ( Double . isNaN ( v2 . y ) ) v2 . y = 0.01 ; v2 . scale ( bondLength / 20.0 ) ; logger . debug ( "Calculation translation vector " + v2 ) ; choice = Math . random ( ) ; if ( choice > 0.5 ) { a2 . getPoint2d ( ) . add ( v2 ) ; logger . debug ( "Random variable: " + choice + ", displacing first atom" ) ; } else { a1 . getPoint2d ( ) . sub ( v2 ) ; logger . debug ( "Random variable: " + choice + ", displacing second atom" ) ; } overlapScore = getOverlapScore ( ac , overlappingAtoms , overlappingBonds ) ; steps ++ ; } while ( overlapScore > 0 && ! ( steps > maxSteps ) ) ; if ( steps < 100 ) { logger . debug ( "Overlap situation resolved" ) ; logger . debug ( "Overlap score: " + overlapScore ) ; logger . debug ( steps + " steps needed to clear situation" ) ; } else { logger . debug ( "Could not resolve overlap situation" ) ; logger . debug ( "Number of " + steps + " steps taken exceeds limit of " + maxSteps ) ; logger . debug ( "Overlap score: " + overlapScore ) ; } return overlapScore ; }
Makes a small displacement to some atoms or rings in the given atomcontainer .