Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
In final
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
gilleain authored and egonw committed Aug 7, 2011
1 parent bd3ca4d commit 78b3d27
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/main/org/openscience/cdk/atomtype/CDKAtomTypeMatcher.java
Expand Up @@ -135,6 +135,8 @@ public IAtomType findMatchingAtomType(IAtomContainer atomContainer, IAtom atom)
type = perceiveGallium(atomContainer, atom);
} else if ("Ge".equals(atom.getSymbol())) {
type = perceiveGermanium(atomContainer, atom);
} else if ("In".equals(atom.getSymbol())) {
type = perceiveIndium(atomContainer, atom);
} else if ("Pu".equals(atom.getSymbol())) {
type = perceivePlutonium(atomContainer, atom);
} else if ("Th".equals(atom.getSymbol())) {
Expand Down Expand Up @@ -1700,6 +1702,23 @@ private IAtomType perceiveCadmium(IAtomContainer atomContainer, IAtom atom) thro
}
return null;
}

private IAtomType perceiveIndium(IAtomContainer atomContainer, IAtom atom) throws CDKException {
if (atom.getFormalCharge() == 0 && atomContainer.getConnectedBondsCount(atom) == 3) {
IAtomType type = getAtomType("In.3");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atom.getFormalCharge() == 3 && atomContainer.getConnectedBondsCount(atom) == 0) {
IAtomType type = getAtomType("In.3plus");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atom.getFormalCharge() == 0 && atomContainer.getConnectedBondsCount(atom) == 1) {
IAtomType type = getAtomType("In.1");
if (isAcceptable(atom, atomContainer, type)) return type;
} else {
IAtomType type = getAtomType("In");
if (isAcceptable(atom, atomContainer, type)) return type;
}
return null;
}

private int countAttachedDoubleBonds(IAtomContainer container, IAtom atom) {
return countAttachedDoubleBonds(container, atom, null);
Expand Down
32 changes: 32 additions & 0 deletions src/main/org/openscience/cdk/dict/data/cdk-atom-types.owl
Expand Up @@ -1692,4 +1692,36 @@
<at:hybridization rdf:resource="&at;sp1"/>
</at:AtomType>

<at:AtomType rdf:ID="In">
<at:formalCharge>0</at:formalCharge>
<at:hasElement rdf:resource="&elem;In"/>
<at:formalNeighbourCount>0</at:formalNeighbourCount>
<at:lonePairCount>0</at:lonePairCount>
<at:piBondCount>0</at:piBondCount>
</at:AtomType>

<at:AtomType rdf:ID="In.1">
<at:formalCharge>0</at:formalCharge>
<at:hasElement rdf:resource="&elem;In"/>
<at:formalNeighbourCount>1</at:formalNeighbourCount>
<at:lonePairCount>0</at:lonePairCount>
<at:piBondCount>2</at:piBondCount>
</at:AtomType>

<at:AtomType rdf:ID="In.3">
<at:formalCharge>0</at:formalCharge>
<at:hasElement rdf:resource="&elem;In"/>
<at:formalNeighbourCount>3</at:formalNeighbourCount>
<at:lonePairCount>0</at:lonePairCount>
<at:piBondCount>0</at:piBondCount>
</at:AtomType>

<at:AtomType rdf:ID="In.3plus">
<at:formalCharge>3</at:formalCharge>
<at:hasElement rdf:resource="&elem;In"/>
<at:formalNeighbourCount>0</at:formalNeighbourCount>
<at:lonePairCount>0</at:lonePairCount>
<at:piBondCount>0</at:piBondCount>
</at:AtomType>

</rdf:RDF>
76 changes: 73 additions & 3 deletions src/test/org/openscience/cdk/atomtype/CDKAtomTypeMatcherTest.java
Expand Up @@ -3688,6 +3688,78 @@ public void testMethylphosphinicAcid() throws Exception {
};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_In_3plus() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"In");
a1.setFormalCharge(3);
mol.addAtom(a1);


String[] expectedTypes = {"In.3plus"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_In_3() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"In");
a1.setFormalCharge(0);
mol.addAtom(a1);
IAtom a2 = builder.newInstance(IAtom.class,"C");
a2.setFormalCharge(0);
mol.addAtom(a2);
IAtom a3 = builder.newInstance(IAtom.class,"C");
a3.setFormalCharge(0);
mol.addAtom(a3);
IAtom a4 = builder.newInstance(IAtom.class,"C");
a4.setFormalCharge(0);
mol.addAtom(a4);
IBond b1 = builder.newInstance(IBond.class,a1, a2, IBond.Order.SINGLE);
mol.addBond(b1);
IBond b2 = builder.newInstance(IBond.class,a1, a3, IBond.Order.SINGLE);
mol.addBond(b2);
IBond b3 = builder.newInstance(IBond.class,a1, a4, IBond.Order.SINGLE);
mol.addBond(b3);


String[] expectedTypes = {"In.3", "C.sp3", "C.sp3", "C.sp3"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_In_1() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"In");
a1.setFormalCharge(0);
mol.addAtom(a1);
IAtom a2 = builder.newInstance(IAtom.class,"C");
a2.setFormalCharge(0);
mol.addAtom(a2);
IBond b1 = builder.newInstance(IBond.class,a1, a2, IBond.Order.TRIPLE);
mol.addBond(b1);


String[] expectedTypes = {"In.1", "C.sp"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_In() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"In");
a1.setFormalCharge(0);
mol.addAtom(a1);


String[] expectedTypes = {"In"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_Cd_2plus() throws Exception {
Expand All @@ -3697,7 +3769,6 @@ public void test_Cd_2plus() throws Exception {
a1.setFormalCharge(2);
mol.addAtom(a1);


String[] expectedTypes = {"Cd.2plus"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}
Expand Down Expand Up @@ -3756,8 +3827,7 @@ public void test_Th() throws Exception {
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"Th");
a1.setFormalCharge(0);
mol.addAtom(a1);

mol.addAtom(a1);

String[] expectedTypes = {"Th"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
Expand Down

0 comments on commit 78b3d27

Please sign in to comment.