private List < Integer > getPermutation ( ) { List < Integer > permutation = new ArrayList < Integer > ( transformedCoords . length ) ; double sum = 0.0f ; for ( Point3d t : transformedCoords ) { List < Integer > neighbors = box . getNeighborsWithCache ( t ) ; int closest = - 1 ; double minDist = Double . MAX_VALUE ; for ( int j : neighbors ) { double dist = t . distanceSquared ( originalCoords [ j ] ) ; if ( dist < minDist ) { closest = j ; minDist = dist ; } } sum += minDist ; if ( closest == - 1 ) { break ; } permutation . add ( closest ) ; } double rmsd = Math . sqrt ( sum / transformedCoords . length ) ; if ( rmsd > distanceThreshold || permutation . size ( ) != transformedCoords . length ) { permutation . clear ( ) ; return permutation ; } // check uniqueness of indices Set < Integer > set = new HashSet < Integer > ( permutation ) ; // if size mismatch, clear permutation (its invalid) if ( set . size ( ) != originalCoords . length ) { permutation . clear ( ) ; } return permutation ; }
Compare this . transformedCoords with the original coords . For each subunit return the transformed subunit with the closest position .