Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For fun, a chiral center finder, and a couple of tests
- Loading branch information
Showing
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package signature.chemistry; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ChiralCenterFinder { | ||
|
||
public static List<Integer> findTetrahedralChiralCenters(Molecule molecule) { | ||
List<Integer> chiralCenterIndices = new ArrayList<Integer>(); | ||
MoleculeSignature molSig = new MoleculeSignature(molecule); | ||
List<String> signatureStrings = molSig.getVertexSignatureStrings(); | ||
for (int i = 0; i < molecule.getAtomCount(); i++) { | ||
int[] connected = molecule.getConnected(i); | ||
if (connected.length < 4) { | ||
continue; | ||
} else { | ||
String s0 = signatureStrings.get(connected[0]); | ||
String s1 = signatureStrings.get(connected[1]); | ||
String s2 = signatureStrings.get(connected[2]); | ||
String s3 = signatureStrings.get(connected[3]); | ||
if (s0.equals(s1) | ||
|| s0.equals(s2) | ||
|| s0.equals(s3) | ||
|| s1.equals(s2) | ||
|| s1.equals(s3) | ||
|| s2.equals(s3)) { | ||
continue; | ||
} else { | ||
chiralCenterIndices.add(i); | ||
} | ||
} | ||
} | ||
|
||
return chiralCenterIndices; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package signature.chemistry; | ||
|
||
import java.util.List; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
|
||
import signature.SymmetryClass; | ||
|
||
public class ChiralityTest { | ||
|
||
@Test | ||
public void spiranTest() { | ||
Molecule mol = new Molecule(); | ||
mol.addAtom("N"); | ||
mol.addMultipleAtoms(12, "C"); | ||
mol.addMultipleAtoms(24, "H"); | ||
mol.addMultipleSingleBonds(0, 1, 4, 5, 8); // central N | ||
mol.addMultipleSingleBonds(1, 2, 33, 34); // ring 1 - CA | ||
mol.addMultipleSingleBonds(2, 3, 11, 15); // ring 1 - CB | ||
mol.addMultipleSingleBonds(3, 4, 12, 16); // ring 1 - CB | ||
mol.addMultipleSingleBonds(4, 35, 36); // ring 1 - CA | ||
mol.addMultipleSingleBonds(5, 6, 29, 30); // ring 2 - CA | ||
mol.addMultipleSingleBonds(6, 7, 9, 13); // ring 2 - CB | ||
mol.addMultipleSingleBonds(7, 8, 10, 14); // ring 2 - CB | ||
mol.addMultipleSingleBonds(8, 31, 32); // ring 2 - CA | ||
mol.addMultipleSingleBonds(9, 17, 18, 19); // CH3 A | ||
mol.addMultipleSingleBonds(10, 20, 21, 22); // CH3 B | ||
mol.addMultipleSingleBonds(11, 23, 24, 25); // CH3 C | ||
mol.addMultipleSingleBonds(12, 26, 27, 28); // CH3 D | ||
|
||
// 7 symmetry classes - central N, CA, CB, CH3-C, HA, HB, CH3-H | ||
MoleculeSignature molSig = new MoleculeSignature(mol); | ||
List<SymmetryClass> symmetryClasses = molSig.getSymmetryClasses(); | ||
Assert.assertEquals(7, symmetryClasses.size()); | ||
|
||
List<Integer> tetraChiralCenters = | ||
ChiralCenterFinder.findTetrahedralChiralCenters(mol); | ||
Assert.assertEquals(4, tetraChiralCenters.size()); | ||
Assert.assertEquals(2, (int)tetraChiralCenters.get(0)); | ||
Assert.assertEquals(3, (int)tetraChiralCenters.get(1)); | ||
Assert.assertEquals(6, (int)tetraChiralCenters.get(2)); | ||
Assert.assertEquals(7, (int)tetraChiralCenters.get(3)); | ||
} | ||
|
||
@Test | ||
public void dichlorocyclopropaneTest() { | ||
Molecule mol = new Molecule(); | ||
mol.addAtom("C"); | ||
mol.addAtom("C"); | ||
mol.addAtom("C"); | ||
mol.addAtom("Cl"); | ||
mol.addAtom("Cl"); | ||
mol.addAtom("H"); | ||
mol.addAtom("H"); | ||
mol.addAtom("H"); | ||
mol.addAtom("H"); | ||
mol.addMultipleSingleBonds(0, 1, 2, 3, 5); | ||
mol.addMultipleSingleBonds(1, 2, 4, 6); | ||
mol.addMultipleSingleBonds(2, 7, 8); | ||
|
||
// 5 symmetry classes - the non-chiral carbon, its hydrogens, the chiral | ||
// carbons, thier hydrogens, and the chlorines. | ||
MoleculeSignature molSig = new MoleculeSignature(mol); | ||
List<SymmetryClass> symmetryClasses = molSig.getSymmetryClasses(); | ||
// System.out.println(symmetryClasses); | ||
Assert.assertEquals(5, symmetryClasses.size()); | ||
|
||
// only two possible chiral centers | ||
List<Integer> tetraChiralCenters = | ||
ChiralCenterFinder.findTetrahedralChiralCenters(mol); | ||
Assert.assertEquals(2, tetraChiralCenters.size()); | ||
Assert.assertEquals(0, (int)tetraChiralCenters.get(0)); | ||
Assert.assertEquals(1, (int)tetraChiralCenters.get(1)); | ||
} | ||
|
||
} |
14196cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For fun?!? I love this! Gilleain++