Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added a cdk.saveCML(List<? extends IMolecules>, String) to save lists…
… of molecules as CML
  • Loading branch information
egonw committed Aug 28, 2011
1 parent 7e5a8d6 commit 00a8777
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
Expand Up @@ -1333,6 +1333,17 @@ public void testSaveMDLMolfile() throws Exception {
));
}

@Test
public void testSaveCMLList() throws Exception {
List<ICDKMolecule> molecules = cdk.createMoleculeList();
molecules.add(cdk.fromSMILES("CCC"));
molecules.add(cdk.fromSMILES("CCO"));
molecules.add(cdk.fromSMILES("COC"));
String path = "/Virtual/testSaveCMLfile" + molecules.hashCode() + ".cml";
cdk.saveCML(molecules, path);
// cannot read it yet, but for now, if it did not crash
}

@Test
public void testSaveCML() throws Exception {
ICDKMolecule propane = cdk.fromSMILES("CCC");
Expand Down
Expand Up @@ -50,7 +50,6 @@
import net.bioclipse.core.domain.IMolecule;
import net.bioclipse.core.domain.IMolecule.Property;
import net.bioclipse.core.domain.RecordableList;
import net.bioclipse.core.domain.SMILESMolecule;
import net.bioclipse.core.util.LogUtils;
import net.bioclipse.jobs.IReturner;
import net.bioclipse.managers.business.IBioclipseManager;
Expand Down Expand Up @@ -911,21 +910,24 @@ public void saveMolecule( IMolecule mol,
*/
public void saveMolecules( List<? extends IMolecule> molecules,
String path,
IChemFormat filetype )
IChemFormat filetype, IProgressMonitor monitor )
throws BioclipseException, CoreException {

saveMolecules( molecules,
ResourcePathTransformer.getInstance().transform(path),
filetype) ;
filetype,
null) ;
}

/**
* Save a list of molecules in SDF or CML
*/
public void saveMolecules( List<? extends IMolecule> molecules,
IFile target,
IChemFormat filetype )
IChemFormat filetype,
IProgressMonitor monitor)
throws BioclipseException, CoreException {
if (monitor == null) monitor = new NullProgressMonitor();

if ( filetype == CMLFormat.getInstance() ||
filetype == MDLV2000Format.getInstance() ||
Expand Down Expand Up @@ -2029,6 +2031,17 @@ public void saveCML(ICDKMolecule cml, String filename)
saveMolecule(cml, filename, (IChemFormat)CMLFormat.getInstance());
}

public void saveCML(List<? extends IMolecule> molecules,
String filename, IProgressMonitor monitor)
throws BioclipseException, InvocationTargetException,
CoreException {
saveMolecules(
molecules, filename,
(IChemFormat)CMLFormat.getInstance(),
monitor
);
}

public void saveMDLMolfile(ICDKMolecule mol, String filename)
throws InvocationTargetException,
BioclipseException,
Expand Down
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.content.IContentType;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemModel;
Expand Down Expand Up @@ -778,6 +777,19 @@ public void saveCML(ICDKMolecule cml, String filename)
BioclipseException,
CoreException;

@Recorded
@PublishedMethod(
params = "List<? extends IMolecule> molecules, String filename",
methodSummary = "Saves a list of molecules in the Chemical Markup Language " +
"format (filename must be relative to workspace " +
"root and folder must exist). Example of file " +
"String: \"/Virtual/bla.cml\"" )
@TestMethods("testSaveCMLList")
public void saveCML(List<? extends IMolecule> molecules, String filename)
throws InvocationTargetException,
BioclipseException,
CoreException;

/**
* Loads molecules from a SMILES file.
*
Expand Down

0 comments on commit 00a8777

Please sign in to comment.