use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.
the class AtomConfigurator method process.
public IAtomContainer process(IAtomContainer mol) throws AmbitException {
if (mol == null)
throw new AmbitException("Null molecule!");
if (mol.getAtomCount() == 0)
throw new AmbitException("No atoms!");
logger.fine("Configuring atom types ...");
// AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(mol.getBuilder());
Iterator<IAtom> atoms = mol.atoms().iterator();
List<String> errors = null;
while (atoms.hasNext()) {
IAtom atom = atoms.next();
if (!(atom instanceof IPseudoAtom))
try {
IAtomType matched = matcher.findMatchingAtomType(mol, atom);
if (matched != null) {
AtomTypeManipulator.configure(atom, matched);
atom.setValency(matched.getValency());
atom.setAtomicNumber(matched.getAtomicNumber());
atom.setExactMass(matched.getExactMass());
} else {
if (errors == null)
errors = new ArrayList<String>();
if (errors.indexOf(atom.getSymbol()) < 0)
errors.add(String.format("%s", atom.getSymbol()));
}
} catch (Exception x) {
if (errors == null)
errors = new ArrayList<String>();
if (errors.indexOf(atom.getSymbol()) < 0) {
errors.add(String.format("%s", atom.getSymbol()));
}
}
}
if ((errors != null) && "true".equals(Preferences.getProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES))) {
Collections.sort(errors);
throw new AmbitException(errors.toString());
}
/*
CDKHueckelAromaticityDetector.detectAromaticity(molecule);
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(mol.getBuilder());
Iterator<IAtom> atoms = mol.atoms();
while (atoms.hasNext()) {
IAtom atom = atoms.next();
IAtomType type = matcher.findMatchingAtomType(mol, atom);
try {
AtomTypeManipulator.configure(atom, type);
logger.debug("Found " + atom.getSymbol() + " of type " + type.getAtomTypeName());
} catch (Exception x) {
logger.error(x.getMessage() + " " + atom.getSymbol(),x);
if ("true".equals(Preferences.getProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES))) {
throw new AmbitException(atom.getSymbol(),x);
}
}
}
*/
atoms = mol.atoms().iterator();
while (atoms.hasNext()) {
IAtom atom = atoms.next();
if ((atom.getAtomicNumber() == null) || (atom.getAtomicNumber() == 0)) {
Integer no = PeriodicTable.getAtomicNumber(atom.getSymbol());
if (no != null)
atom.setAtomicNumber(no.intValue());
}
}
return mol;
}
use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.
the class AtomEnvironmentDescriptor method atomTypeToString.
public String atomTypeToString(int index) {
IAtomType aType = getAtomType(index);
String atomS = null;
if (aType == null)
atomS = "Misc";
else
atomS = aType.getAtomTypeName();
return atomS;
}
use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.
the class AtomEnvironmentDescriptorTest method testHybridizationStateATMatcher.
@Test
public void testHybridizationStateATMatcher() throws Exception {
IAtomContainer mol = getMol();
SybylAtomTypeMatcher h = SybylAtomTypeMatcher.getInstance(SilentChemObjectBuilder.getInstance());
for (int i = 0; i < mol.getAtomCount(); i++) {
IAtomType a = h.findMatchingAtomType(mol, mol.getAtom(i));
Assert.assertTrue(a != null);
}
}
use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.
the class AtomEnvironentMatrix method initAtomTypes.
protected String[] initAtomTypes(AtomTypeFactory factory, IAtomTypeMatcher atm) throws CDKException {
// the idea is not to create objects if they already exist...
if ((atm == null) || (factory == null)) {
if (this.atm == null) {
this.atm = SybylAtomTypeMatcher.getInstance(SilentChemObjectBuilder.getInstance());
try {
InputStream ins = getAtomTypeFactoryStream();
this.factory = AtomTypeFactory.getInstance(ins, "owl", SilentChemObjectBuilder.getInstance());
} catch (Exception x) {
throw new CDKException(x.getMessage());
}
empty = true;
} else
empty = false;
} else {
this.atm = atm;
this.factory = factory;
empty = true;
}
if (empty) {
atomTypes = this.factory.getAllAtomTypes();
if (map == null)
map = new TreeMap<String, Integer>();
else
map.clear();
for (int i = 0; i < atomTypes.length; i++) {
map.put(atomTypes[i].getAtomTypeName(), new Integer(i));
}
}
// descriptorNames
Set<String> dNames = new TreeSet<String>();
String key = getKeyLevel0(null);
if (!dNames.contains(key))
dNames.add(key);
for (int x1 = 0; x1 < atomTypes.length; x1++) {
IAtomType key1 = atomTypes[x1];
key = getKeyLevel0(key1);
if (!dNames.contains(key))
dNames.add(key);
for (int x2 = x1; x2 < atomTypes.length; x2++) {
IAtomType key2 = atomTypes[x2];
for (int l = 1; l <= 8; l++) {
key = getKeyLevel(key1, key2, l);
if (!dNames.contains(key))
dNames.add(key);
}
}
for (int l = 1; l <= 8; l++) {
key = getKeyLevel(key1, null, l);
if (!dNames.contains(key))
dNames.add(key);
}
}
// Collections.sort(dNames);
return dNames.toArray(new String[dNames.size()]);
}
use of org.openscience.cdk.interfaces.IAtomType in project ambit-mirror by ideaconsult.
the class AtomEnvironentMatrix method doCalculation.
/**
* @param arg0
* @param result
* result[i] contains the level at which ith atom is from the
* current atom (one set by setParameters)
* @throws CDKException
*/
public HashIntDescriptorResult doCalculation(IAtomContainer atomContainer) throws CDKException {
HashIntDescriptorResult sparseMatrix = null;
try {
sparseMatrix = new HashIntDescriptorResult(new TreeMap<String, Integer>());
sparseMatrix.setMaxLevels(getMaxLevel());
sparseMatrix.setFactory(factoryResource.substring(factoryResource.lastIndexOf("/") + 1));
} catch (Exception x) {
throw new CDKException(x.getMessage());
}
if ((atm == null) || (factory == null))
descriptorNames = initAtomTypes(null, null);
// maxLevel is how many bonds from the atom we will count atom types
int natoms = atomContainer.getAtomCount();
// do atom type matching
atomTypes = factory.getAllAtomTypes();
/*
* System.out.println("AtomTypes"); for (IAtomType at :atomTypes) {
* System.out.print(at.getAtomTypeName());System.out.print("\t");}
* System.out.println("End AtomTypes");
*/
// array of atom type integers
int[] atomIndex = new int[natoms];
for (int i = 0; i < natoms; i++) try {
IAtomType a = atm.findMatchingAtomType(atomContainer, atomContainer.getAtom(i));
if (a != null) {
Object mappedType = map.get(a.getAtomTypeName());
if (mappedType != null) {
atomIndex[i] = ((Integer) mappedType).intValue();
} else {
atomIndex[i] = -1;
}
} else {
// not found
atomIndex[i] = -1;
}
String key = getKeyLevel0(atomIndex[i] >= 0 ? atomTypes[atomIndex[i]] : null);
add(sparseMatrix.getResults(), key);
if (addGenericTypes) {
if ((atomIndex[i] > 0) && atomTypes[atomIndex[i]] != null) {
if (isHal(atomTypes[atomIndex[i]]))
add(sparseMatrix.getResults(), "L0_Hal");
if (isHet(atomTypes[atomIndex[i]]))
add(sparseMatrix.getResults(), "L0_Het");
if (isHev(atomTypes[atomIndex[i]]))
add(sparseMatrix.getResults(), "L0_Hev");
}
add(sparseMatrix.getResults(), "L0_Any");
}
} catch (Exception x) {
// x.printStackTrace();
throw new CDKException(x.getMessage() + "\ninitConnectionMatrix");
}
// compute bond distances between all atoms
int[][] aMatrix = PathTools.computeFloydAPSP(AdjacencyMatrix.getMatrix(atomContainer));
for (int i = 0; i < natoms; i++) {
IAtomType key1 = atomIndex[i] >= 0 ? atomTypes[atomIndex[i]] : null;
for (int j = i; j < natoms; j++) {
IAtomType key2 = atomIndex[j] >= 0 ? atomTypes[atomIndex[j]] : null;
if (aMatrix[i][j] > 0 && (aMatrix[i][j] != 999999999) && (aMatrix[i][j] <= maxLevel)) {
// j is not atom i and bonds less or
// equal to maxlevel
String key = getKeyLevel(key1, key2, aMatrix[i][j]);
add(sparseMatrix.getResults(), key);
}
}
}
return sparseMatrix;
}
Aggregations