Skip to content

Commit

Permalink
Br 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 11, 2011
1 parent 8cf1d4d commit 81c629a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 39 deletions.
86 changes: 47 additions & 39 deletions src/main/org/openscience/cdk/atomtype/CDKAtomTypeMatcher.java
Expand Up @@ -153,6 +153,8 @@ public IAtomType findMatchingAtomType(IAtomContainer atomContainer, IAtom atom)
type = perceiveGadolinum(atomContainer, atom);
} else if ("Ge".equals(atom.getSymbol())) {
type = perceiveGermanium(atomContainer, atom);
} else if ("Br".equals(atom.getSymbol())) {
type = perceiveBromine(atomContainer, atom);
} else if ("V".equals(atom.getSymbol())) {
type = perceiveVanadium(atomContainer, atom);
} else if ("Ti".equals(atom.getSymbol())) {
Expand Down Expand Up @@ -1323,45 +1325,7 @@ private IAtomType perceiveLithium(IAtomContainer atomContainer, IAtom atom)

private IAtomType perceiveHalogens(IAtomContainer atomContainer, IAtom atom)
throws CDKException {
if ("Br".equals(atom.getSymbol())) {
if (hasOneSingleElectron(atomContainer, atom)) {
if (atomContainer.getConnectedBondsCount(atom) == 0) {
if (atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == +1) {
IAtomType type = getAtomType("Br.plus.radical");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atom.getFormalCharge() == CDKConstants.UNSET ||
atom.getFormalCharge() == 0) {
IAtomType type = getAtomType("Br.radical");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if (atomContainer.getConnectedBondsCount(atom) <= 1) {
IBond.Order maxBondOrder = atomContainer.getMaximumBondOrder(atom);
if (maxBondOrder == IBond.Order.SINGLE) {
IAtomType type = getAtomType("Br.plus.radical");
if (isAcceptable(atom, atomContainer, type)) return type;
}
}
return null;
} else if ((atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == -1)) {
IAtomType type = getAtomType("Br.minus");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atom.getFormalCharge() == 1) {
IBond.Order maxBondOrder = atomContainer.getMaximumBondOrder(atom);
if (maxBondOrder == IBond.Order.DOUBLE) {
IAtomType type = getAtomType("Br.plus.sp2");
if (isAcceptable(atom, atomContainer, type)) return type;
}else if (maxBondOrder == IBond.Order.SINGLE){
IAtomType type = getAtomType("Br.plus.sp3");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if (atomContainer.getConnectedBondsCount(atom) == 1 ||
atomContainer.getConnectedBondsCount(atom) == 0) {
IAtomType type = getAtomType("Br");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if ("F".equals(atom.getSymbol())) {
if ("F".equals(atom.getSymbol())) {
if (hasOneSingleElectron(atomContainer, atom)) {
if (atomContainer.getConnectedBondsCount(atom) == 0) {
if (atom.getFormalCharge() != CDKConstants.UNSET &&
Expand Down Expand Up @@ -2311,6 +2275,50 @@ private IAtomType perceiveVanadium(IAtomContainer atomContainer, IAtom atom) thr
}
return null;
}

private IAtomType perceiveBromine(IAtomContainer atomContainer, IAtom atom) throws CDKException {
if (hasOneSingleElectron(atomContainer, atom)) {
if (atomContainer.getConnectedBondsCount(atom) == 0) {
if (atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == +1) {
IAtomType type = getAtomType("Br.plus.radical");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atom.getFormalCharge() == CDKConstants.UNSET ||
atom.getFormalCharge() == 0) {
IAtomType type = getAtomType("Br.radical");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if (atomContainer.getConnectedBondsCount(atom) <= 1) {
IBond.Order maxBondOrder = atomContainer.getMaximumBondOrder(atom);
if (maxBondOrder == IBond.Order.SINGLE) {
IAtomType type = getAtomType("Br.plus.radical");
if (isAcceptable(atom, atomContainer, type)) return type;
}
}
return null;
} else if ((atom.getFormalCharge() != CDKConstants.UNSET &&
atom.getFormalCharge() == -1)) {
IAtomType type = getAtomType("Br.minus");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atom.getFormalCharge() == 1) {
IBond.Order maxBondOrder = atomContainer.getMaximumBondOrder(atom);
if (maxBondOrder == IBond.Order.DOUBLE) {
IAtomType type = getAtomType("Br.plus.sp2");
if (isAcceptable(atom, atomContainer, type)) return type;
}else if (maxBondOrder == IBond.Order.SINGLE){
IAtomType type = getAtomType("Br.plus.sp3");
if (isAcceptable(atom, atomContainer, type)) return type;
}
} else if (atomContainer.getConnectedBondsCount(atom) == 1 ||
atomContainer.getConnectedBondsCount(atom) == 0) {
IAtomType type = getAtomType("Br");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (atomContainer.getConnectedBondsCount(atom) == 3) {
IAtomType type = getAtomType("Br.3");
if (isAcceptable(atom, atomContainer, type)) return type;
}
return null;
}

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

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

<at:AtomType rdf:ID="P.se.3">
<at:formalCharge>0</at:formalCharge>
<at:hasElement rdf:resource="&elem;P"/>
Expand Down
33 changes: 33 additions & 0 deletions src/test/org/openscience/cdk/atomtype/CDKAtomTypeMatcherTest.java
Expand Up @@ -3520,6 +3520,39 @@ public void testPine() throws Exception {
}
}

/**
* Bromic acid (CHEBI:49382).
*
* @cdk.inchi InChI=1S/BrHO3/c2-1(3)4/h(H,2,3,4)
*/
@Test
public void test_Br_3() throws Exception {
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IMolecule mol = builder.newInstance(IMolecule.class);
IAtom a1 = builder.newInstance(IAtom.class,"Br");
a1.setFormalCharge(0);
mol.addAtom(a1);
IAtom a2 = builder.newInstance(IAtom.class,"O");
a2.setFormalCharge(0);
mol.addAtom(a2);
IAtom a3 = builder.newInstance(IAtom.class,"O");
a3.setFormalCharge(0);
mol.addAtom(a3);
IAtom a4 = builder.newInstance(IAtom.class,"O");
a4.setFormalCharge(0);
mol.addAtom(a4);
IBond b1 = builder.newInstance(IBond.class,a1, a2, IBond.Order.DOUBLE);
mol.addBond(b1);
IBond b2 = builder.newInstance(IBond.class,a1, a3, IBond.Order.DOUBLE);
mol.addBond(b2);
IBond b3 = builder.newInstance(IBond.class,a1, a4, IBond.Order.SINGLE);
mol.addBond(b3);


String[] expectedTypes = {"Br.3", "O.sp2", "O.sp2", "O.sp3"};
assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}

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

0 comments on commit 81c629a

Please sign in to comment.