Skip to content

Commit

Permalink
Pt final
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
gilleain authored and egonw committed Sep 3, 2011
1 parent 177e5bd commit cc46f63
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 19 deletions.
52 changes: 33 additions & 19 deletions src/main/org/openscience/cdk/atomtype/CDKAtomTypeMatcher.java
Expand Up @@ -143,6 +143,8 @@ public IAtomType findMatchingAtomType(IAtomContainer atomContainer, IAtom atom)
type = perceiveGallium(atomContainer, atom);
} else if ("Ge".equals(atom.getSymbol())) {
type = perceiveGermanium(atomContainer, atom);
} else if ("Pt".equals(atom.getSymbol())) {
type = perceivePlatinum(atomContainer, atom);
} else if ("Hg".equals(atom.getSymbol())) {
type = perceiveMercury(atomContainer, atom);
} else if ("Fe".equals(atom.getSymbol())) {
Expand Down Expand Up @@ -1425,25 +1427,6 @@ private IAtomType perceiveCommonSalts(IAtomContainer atomContainer, IAtom atom)
IAtomType type = getAtomType("Co.metallic");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if ("Pt".equals(atom.getSymbol())) {
if (hasOneSingleElectron(atomContainer, atom)) {
// no idea how to deal with this yet
return null;
} else if ((atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == +2)) {
IAtomType type = getAtomType("Pt.2plus");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if ((atom.getFormalCharge() == CDKConstants.UNSET ||
atom.getFormalCharge() == 0)) {
int neighbors = atomContainer.getConnectedAtomsCount(atom);
if (neighbors == 4) {
IAtomType type = getAtomType("Pt.4");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (neighbors == 6) {
IAtomType type = getAtomType("Pt.6");
if (isAcceptable(atom, atomContainer, type)) return type;
}
}
} else if ("Ni".equals(atom.getSymbol())) {
if (hasOneSingleElectron(atomContainer, atom)) {
// no idea how to deal with this yet
Expand Down Expand Up @@ -2034,6 +2017,37 @@ private IAtomType perceiveCalcium(IAtomContainer atomContainer, IAtom atom) thro
}
return null;
}

private IAtomType perceivePlatinum(IAtomContainer atomContainer, IAtom atom) throws CDKException {
if (hasOneSingleElectron(atomContainer, atom)) {
// no idea how to deal with this yet
return null;
} else if ((atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == +2)) {
int neighbors = atomContainer.getConnectedAtomsCount(atom);
if (neighbors == 4) {
IAtomType type = getAtomType("Pt.2plus.4");
if (isAcceptable(atom, atomContainer, type)) return type;
} else {
IAtomType type = getAtomType("Pt.2plus");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if ((atom.getFormalCharge() == CDKConstants.UNSET ||
atom.getFormalCharge() == 0)) {
int neighbors = atomContainer.getConnectedAtomsCount(atom);
if (neighbors == 2) {
IAtomType type = getAtomType("Pt.2");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (neighbors == 4) {
IAtomType type = getAtomType("Pt.4");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (neighbors == 6) {
IAtomType type = getAtomType("Pt.6");
if (isAcceptable(atom, atomContainer, type)) return type;
}
}
return null;
}

private int countAttachedDoubleBonds(IAtomContainer container, IAtom atom) {
return countAttachedDoubleBonds(container, atom, null);
Expand Down
14 changes: 14 additions & 0 deletions src/main/org/openscience/cdk/dict/data/cdk-atom-types.owl
Expand Up @@ -1396,6 +1396,20 @@
<at:formalNeighbourCount>6</at:formalNeighbourCount>
<at:piBondCount>0</at:piBondCount>
</at:AtomType>

<at:AtomType rdf:ID="Pt.2plus.4">
<at:formalCharge>2</at:formalCharge>
<at:hasElement rdf:resource="&elem;Pt"/>
<at:formalNeighbourCount>4</at:formalNeighbourCount>
<at:piBondCount>0</at:piBondCount>
</at:AtomType>

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

<at:AtomType rdf:ID="Co.2plus">
<at:formalCharge>2</at:formalCharge>
Expand Down
56 changes: 56 additions & 0 deletions src/test/org/openscience/cdk/atomtype/CDKAtomTypeMatcherTest.java
Expand Up @@ -3896,6 +3896,62 @@ public void testMethylphosphinicAcid() throws Exception {
};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}


@Test
public void test_Pt_2() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"Pt");
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);
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);


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

@Test
public void test_Pt_2plus_4() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"Pt");
a1.setFormalCharge(2);
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);
IAtom a5 = builder.newInstance(IAtom.class,"C");
a5.setFormalCharge(0);
mol.addAtom(a5);
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);
IBond b4 = builder.newInstance(IBond.class,a1, a5, IBond.Order.SINGLE);
mol.addBond(b4);

String[] expectedTypes = {"Pt.2plus.4", "C.sp3", "C.sp3", "C.sp3", "C.sp3"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_Cu_metallic() throws Exception {
Expand Down

0 comments on commit cc46f63

Please sign in to comment.