@@ -104,28 +104,42 @@ private void mcsBuilder(IAtomContainer mol1, IAtomContainer mol2) throws CDKExce
104104 }
105105
106106 /**
107- * Delegates MCS computation to SMSD 3.0.0.
107+ * Delegates MCS computation to SMSD.
108+ * First tries a fast substructure check; if that fails, falls back to full MCS.
108109 */
109110 private void smsdMCSAlgorithm (IAtomContainer mol1 , IAtomContainer mol2 ) throws CDKException {
110111 try {
111- // First try substructure check
112- if (mol1 .getAtomCount () > 1 && mol2 .getAtomCount () > 1 ) {
113- Substructure sub ;
114- if (mol1 instanceof IQueryAtomContainer ) {
115- sub = new Substructure ((IQueryAtomContainer ) mol1 , mol2 , atomMatcher , bondMatcher , true );
116- } else {
117- sub = new Substructure (mol1 , mol2 , atomMatcher , bondMatcher , true );
118- }
119- if (sub .isSubgraph ()) {
112+ ChemOptions chemOptions = buildChemOptions ();
113+ SMSD smsd = new SMSD (mol1 , mol2 , chemOptions );
114+
115+ // Fast substructure check before expensive MCS
116+ if (smsd .isSubstructure (5000 )) {
117+ java .util .List <Map <Integer , Integer >> subResults = smsd .findAllSubstructures (1 , 5000 );
118+ if (subResults != null && !subResults .isEmpty ()) {
120119 clearMaps ();
121- getMCSList ().addAll (sub .getAllAtomMapping ());
120+ for (Map <Integer , Integer > mapping : subResults ) {
121+ AtomAtomMapping aam = new AtomAtomMapping (mol1 , mol2 );
122+ for (Map .Entry <Integer , Integer > entry : mapping .entrySet ()) {
123+ int qIdx = entry .getKey ();
124+ int tIdx = entry .getValue ();
125+ if (qIdx >= 0 && qIdx < mol1 .getAtomCount ()
126+ && tIdx >= 0 && tIdx < mol2 .getAtomCount ()) {
127+ IAtom qAtom = mol1 .getAtom (qIdx );
128+ IAtom tAtom = mol2 .getAtom (tIdx );
129+ if (qAtom != null && tAtom != null ) {
130+ aam .put (qAtom , tAtom );
131+ }
132+ }
133+ }
134+ if (!aam .isEmpty ()) {
135+ getMCSList ().add (aam );
136+ }
137+ }
122138 return ;
123139 }
124140 }
125141
126- // Fall back to MCS via SMSD 3.4.0
127- ChemOptions chemOptions = new ChemOptions ();
128- SMSD smsd = new SMSD (mol1 , mol2 , chemOptions );
142+ // Fall back to full MCS
129143 Map <Integer , Integer > mcsResult = smsd .findMCS ();
130144
131145 clearMaps ();
0 commit comments