Created
February 26, 2010 00:35
-
-
Save rajarshi/315246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gov.nih.ncgc; | |
import chemaxon.formats.MolImporter; | |
import chemaxon.sss.search.MCS; | |
import chemaxon.struc.Molecule; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Print out the MCS of a set of molecules as a SMILES string. | |
* | |
* @author Rajarshi Guha | |
*/ | |
public class DumpMCS { | |
private Molecule mcs; | |
private List<Molecule> mols = null; | |
public DumpMCS() { | |
} | |
public DumpMCS(List<Molecule> mols) { | |
this.mols = new ArrayList<Molecule>(mols); | |
} | |
public Molecule getMCS() { | |
return mcs; | |
} | |
public void setMols(List<Molecule> mols) { | |
this.mols = new ArrayList<Molecule>(mols); | |
} | |
public void run() throws IOException, InterruptedException { | |
if (mols == null) throw new IOException("Must set the molecules to process"); | |
if (mols.size() == 1) { | |
mcs = mols.get(0); | |
return; | |
} | |
List<Molecule> mcses = new ArrayList<Molecule>(); | |
for (int i = 0; i < mols.size(); i++) { | |
for (int j = 0; j < mols.size(); j++) { | |
if (i == j) continue; | |
MCS mcs = new MCS(); | |
mcs.setMolecules(mols.get(i), mols.get(j)); | |
mcs.search(); | |
Molecule tmp = mcs.getResultAsMolecule(); | |
if (tmp != null) | |
mcses.add(tmp); | |
} | |
} | |
int indexOfBiggest = -1; | |
int maxSize = -1; | |
int i = 0; | |
for (Molecule mol : mcses) { | |
if (mol.getAtomCount() > maxSize) { | |
maxSize = mol.getAtomCount(); | |
indexOfBiggest = i; | |
} | |
i++; | |
} | |
mcs = mcses.get(indexOfBiggest); | |
} | |
public static void main(String[] args) throws IOException, InterruptedException { | |
if (args.length != 1) { | |
System.out.println("Must specify a SMILES file as the single argument"); | |
System.exit(-1); | |
} | |
List<Molecule> mols = new ArrayList<Molecule>(); | |
MolImporter mi = new MolImporter(args[0]); | |
for (Molecule mol; (mol = mi.read()) != null;) { | |
mols.add(mol); | |
} | |
mi.close(); | |
DumpMCS dmcs = new DumpMCS(mols); | |
dmcs.run(); | |
System.out.println(dmcs.getMCS().toFormat("smiles")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment