Skip to content

Commit

Permalink
Added modifications and unit test for alias atom naming patch
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
John May authored and egonw committed Dec 9, 2011
1 parent 23132a0 commit bd4b094
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/org/openscience/cdk/io/MDLV2000Reader.java
Expand Up @@ -720,12 +720,19 @@ private IMolecule readMolecule(IMolecule molecule) throws CDKException {
int aliasAtomNumber = Integer.parseInt(line.replaceFirst("A\\s{1,4}", "")) - RGroupCounter;
line = input.readLine(); linecount++;
String[] aliasArray = line.split("\\\\");
// name of the alias atom like R1 odr R2 etc.
// name of the alias atom like R1 or R2 etc.
String alias = "";
for (int i = 0; i < aliasArray.length; i++) {
alias += aliasArray[i];
}
IAtom aliasAtom = molecule.getAtom(aliasAtomNumber);

// skip if already a pseudoatom
if(aliasAtom instanceof IPseudoAtom){
((IPseudoAtom) aliasAtom).setLabel(alias);
continue;
}

IAtom newPseudoAtom = molecule.getBuilder().newInstance(IPseudoAtom.class,alias);
if(aliasAtom.getPoint2d() != null) {
newPseudoAtom.setPoint2d(aliasAtom.getPoint2d());
Expand Down
20 changes: 19 additions & 1 deletion src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java
Expand Up @@ -884,6 +884,24 @@ public void testDeuterium() throws Exception {
MDLV2000Reader reader = new MDLV2000Reader(in);
IMolecule molecule = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class);
reader.read(molecule);
Assert.assertEquals("R", molecule.getAtom(55).getSymbol() );
Assert.assertEquals("R", molecule.getAtom(55).getSymbol());
}

@Test
public void testAliasAtomNaming() throws Exception {
InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/mol_testAliasAtomNaming.mol");
MDLV2000Reader reader = new MDLV2000Reader(in);
IMolecule molecule = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class);
reader.read(molecule);

IAtom[] atoms = AtomContainerManipulator.getAtomArray(molecule);


for (IAtom atom : atoms) {
if (atom instanceof IPseudoAtom) {
Assert.assertEquals("R1", ((IPseudoAtom) atom).getLabel());
}
}

}
}

0 comments on commit bd4b094

Please sign in to comment.