@@ -353,6 +353,7 @@ private void checkReactionBalance() throws IOException {
353353 }
354354 }
355355
356+ @ SuppressWarnings ("deprecation" )
356357 private void calculateAtomAtomMapping () throws IOException , Exception {
357358
358359 try {
@@ -790,6 +791,7 @@ private List<IAtom> markHAroundCoreAtoms(String id, IAtomContainerSet molSet) {
790791 * @param molSet
791792 * @return
792793 */
794+ @ SuppressWarnings ("deprecation" )
793795 private List <IAtom > collectUnMappedSingleHAtoms (IAtomContainerSet molSet ) {
794796
795797 List <IAtom > list = new ArrayList <>();
@@ -836,6 +838,7 @@ private List<IAtom> collectUnMappedHAtoms(IAtomContainerSet molSet) {
836838 * @param counter
837839 * @return updated Counter
838840 */
841+ @ SuppressWarnings ("deprecation" )
839842 private int markUnMappedHAtoms (IReaction mappedReaction , int counter ) {
840843
841844 int localCounter = counter ;
@@ -1185,13 +1188,14 @@ private IAtomContainer prepareMol(IAtomContainer cloneMolecule)
11851188 */
11861189 private void permuteWithoutClone (int [] p , IAtomContainer atomContainer ) {
11871190 int n = atomContainer .getAtomCount ();
1191+ int [] permutation = normalizePermutation (p , n );
11881192 LOGGER .debug ("permuting " + java .util .Arrays .toString (p ));
11891193 IAtom [] permutedAtoms = new IAtom [n ];
11901194
11911195 for (int i = 0 ; i < n ; i ++) {
11921196 IAtom atom = atomContainer .getAtom (i );
1193- permutedAtoms [p [i ]] = atom ;
1194- atom .setProperty ("label" , p [i ]);
1197+ permutedAtoms [permutation [i ]] = atom ;
1198+ atom .setProperty ("label" , permutation [i ]);
11951199 }
11961200 atomContainer .setAtoms (permutedAtoms );
11971201
@@ -1222,6 +1226,29 @@ private void permuteWithoutClone(int[] p, IAtomContainer atomContainer) {
12221226 atomContainer .setBonds (bonds );
12231227 }
12241228
1229+ private int [] normalizePermutation (int [] permutation , int size ) {
1230+ if (permutation == null || permutation .length != size ) {
1231+ return identityPermutation (size );
1232+ }
1233+
1234+ boolean [] seen = new boolean [size ];
1235+ for (int value : permutation ) {
1236+ if (value < 0 || value >= size || seen [value ]) {
1237+ return identityPermutation (size );
1238+ }
1239+ seen [value ] = true ;
1240+ }
1241+ return permutation ;
1242+ }
1243+
1244+ private int [] identityPermutation (int size ) {
1245+ int [] identity = new int [size ];
1246+ for (int i = 0 ; i < size ; i ++) {
1247+ identity [i ] = i ;
1248+ }
1249+ return identity ;
1250+ }
1251+
12251252 /**
12261253 * Old Atom Rank in the reactant mapped to new Rank
12271254 *
@@ -1705,6 +1732,7 @@ public static class MappingHandler extends BasicDebugger {
17051732 *
17061733 * @param MappedReaction
17071734 */
1735+ @ SuppressWarnings ("deprecation" )
17081736 public static void cleanMapping (IReaction MappedReaction ) {
17091737 int count = MappedReaction .getMappingCount ();
17101738 for (int i = count - 1 ; i >= 0 ; i --) {
@@ -1741,6 +1769,7 @@ public static void cleanMapping(IReaction MappedReaction) {
17411769 * @param counter
17421770 * @return
17431771 */
1772+ @ SuppressWarnings ("deprecation" )
17441773 protected static int setMappingFlags (IReaction expLabReaction , IReaction MappedReaction , int counter ) {
17451774 IAtomContainerSet expEductSet = expLabReaction .getReactants ();
17461775 IAtomContainerSet expProductSet = expLabReaction .getProducts ();
@@ -1820,6 +1849,7 @@ protected static int setMappingFlags(IReaction expLabReaction, IReaction MappedR
18201849 * @param counter
18211850 * @return
18221851 */
1852+ @ SuppressWarnings ("deprecation" )
18231853 protected static int setMappingFlags (IReaction MappedReaction , IReaction ReactionWithUniqueSTOICHIOMETRY , IReaction coreMappedReaction , int counter ) {
18241854 IAtomContainerSet expEductSet = ReactionWithUniqueSTOICHIOMETRY .getReactants ();
18251855 IAtomContainerSet expProductSet = ReactionWithUniqueSTOICHIOMETRY .getProducts ();
0 commit comments