Skip to content

Commit

Permalink
Mg final
Browse files Browse the repository at this point in the history
  • Loading branch information
gilleain authored and egonw committed Sep 4, 2011
1 parent 00e9aac commit c562129
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/org/openscience/cdk/atomtype/CDKAtomTypeMatcher.java
Expand Up @@ -2100,6 +2100,34 @@ private IAtomType perceiveGadolinum(IAtomContainer atomContainer, IAtom atom) th
return null;
}

private IAtomType perceiveMagnesium(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() == 0)) {
int neighbors = atomContainer.getConnectedAtomsCount(atom);
if (neighbors == 4) {
IAtomType type = getAtomType("Mg.neutral");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (neighbors == 2) {
IAtomType type = getAtomType("Mg.neutral.2");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (neighbors == 1) {
IAtomType type = getAtomType("Mg.neutral.1");
if (isAcceptable(atom, atomContainer, type)) return type;
} else {
IAtomType type = getAtomType("Mg.neutral");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if ((atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == +2)) {
IAtomType type = getAtomType("Mg.2plus");
if (isAcceptable(atom, atomContainer, type)) return type;
}
return null;
}

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

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

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

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

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

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

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

@Test
public void test_Mg_neutral_4() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"C");
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,"Mg");
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,a2, a3, 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,a3, a4, IBond.Order.SINGLE);
mol.addBond(b3);
IBond b4 = builder.newInstance(IBond.class,a3, a5, IBond.Order.SINGLE);
mol.addBond(b4);


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

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


String[] expectedTypes = {"Mg.neutral.1", "C.sp2"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

@Test
public void test_Gd_3plus() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
Expand Down

0 comments on commit c562129

Please sign in to comment.