use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.
the class StructureQueryResource method getSMILES.
protected String getSMILES(Form form, boolean aromatic) throws ResourceException {
String query_smiles;
String search_arg = form.getFirstValue(QueryResource.search_param);
String searchb64_arg = form.getFirstValue(QueryResource.b64search_param);
QueryType query_type = getQueryType(form, search_arg);
switch(query_type) {
case mol:
{
query_smiles = searchb64_arg;
if (query_smiles != null) {
query_smiles = new String(Base64.decode(query_smiles));
} else
query_smiles = search_arg;
try {
IAtomContainer ac = MoleculeTools.readMolfile(query_smiles);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac);
if (hadder == null) {
hadder = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
}
hadder.addImplicitHydrogens(ac);
return SmilesGenerator.generic().create(ac);
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
}
}
case smiles:
{
query_smiles = searchb64_arg;
if (query_smiles != null) {
query_smiles = new String(Base64.decode(query_smiles));
} else
query_smiles = search_arg;
return query_smiles == null ? null : query_smiles.trim();
}
case url:
try {
if (search_arg == null)
return null;
query_smiles = search_arg.trim();
if (query_smiles == null)
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Empty query");
IAtomContainer mol = getFromURI(query_smiles.trim());
AtomConfigurator c = new AtomConfigurator();
mol = c.process(mol);
ambit2.core.helper.CDKHueckelAromaticityDetector.detectAromaticity(mol);
SmilesGenerator g = SmilesGenerator.generic();
if (aromatic)
g = g.aromatic();
return g.create(mol);
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
}
default:
return null;
}
}
use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.
the class AtomConfiguratorProcessorTest method test.
/**
* Atom configurator sets number of properties,which are otherwise uninitialized
* @throws Exception
*/
@Test
public void test() throws Exception {
AtomConfigurator p = new AtomConfigurator();
IAtomContainer mol = MoleculeFactory.makeBenzene();
int uninitialized = 0;
for (int i = 0; i < mol.getAtomCount(); i++) {
if (mol.getAtom(i).getAtomicNumber() == null || mol.getAtom(i).getHybridization() == null)
uninitialized++;
}
if (uninitialized > 0) {
mol = p.process(mol);
for (int i = 0; i < mol.getAtomCount(); i++) {
Assert.assertEquals(6, mol.getAtom(i).getAtomicNumber().intValue());
Assert.assertEquals(Hybridization.SP2, mol.getAtom(i).getHybridization());
Assert.assertNotNull(mol.getAtom(i).getValency());
}
}
}
use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.
the class QuerySMARTS method prepareScreening.
public void prepareScreening() throws AmbitException {
try {
if (((screening.getValue() == null) && isFp1024_screening()) || ((screening.getFieldname() == null)) && isSk1024_screening()) {
// if ((screening.getValue()==null) || (screening.getFieldname()==null)) {
screening.setPageSize(0);
screening.setPage(0);
SmartsPatternAmbit matcher = new SmartsPatternAmbit(builder);
matcher.setUseCDKIsomorphism(false);
value.setQuery(matcher);
IQueryAtomContainer container = matcher.getQuery();
IAtomContainer atomContainer = smartsToChemObject.process(container);
try {
AtomConfigurator cfg = new AtomConfigurator();
cfg.process(atomContainer);
} catch (Exception x) {
logger.log(Level.FINE, x.getMessage(), x);
}
try {
CDKHueckelAromaticityDetector.detectAromaticity(atomContainer);
} catch (Exception x) {
logger.log(Level.FINE, x.getMessage(), x);
}
if ((atomContainer == null) || (atomContainer.getAtomCount() == 0)) {
screening.setValue(null);
screening.setFieldname(null);
} else {
try {
screening.setValue(fp1024_screening ? fpGenerator.process(atomContainer) : null);
} catch (Exception x) {
screening.setValue(null);
}
try {
screening.setFieldname(sk1024_screening ? skGenerator.process(atomContainer) : null);
} catch (Exception x) {
screening.setFieldname(null);
}
}
}
} catch (AmbitException x) {
throw x;
// screening.setValue(null);
// screening.setFieldname(null);
}
}
use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.
the class DbReaderTest method testProcess.
@Test
public void testProcess() throws Exception {
setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
IDatabaseConnection c = getConnection();
ITable names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
Assert.assertEquals(5, names.getRowCount());
ITable values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
Assert.assertEquals(2, values.getRowCount());
ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> p = new ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor>();
p.add(new ProcessorStructureRetrieval());
p.add(new IProcessor<IStructureRecord, IStructureRecord>() {
public boolean isEnabled() {
return true;
}
public IStructureRecord process(IStructureRecord target) throws AmbitException {
// System.out.println(target.getContent());
return target;
}
public void setEnabled(boolean value) {
}
public long getID() {
return 0;
}
@Override
public void open() throws Exception {
}
@Override
public void close() throws Exception {
}
});
p.add(new MoleculeReader());
p.add(new AtomConfigurator());
p.add(new FunctionalGroup("Test", "P", "Test"));
p.add(new IProcessor<VerboseDescriptorResult, String>() {
/**
*/
private static final long serialVersionUID = -3923864774580483348L;
public String process(VerboseDescriptorResult target) throws AmbitException {
Assert.assertEquals("1", target.getResult().toString());
return target.toString();
}
public boolean isEnabled() {
return true;
}
public void setEnabled(boolean value) {
}
public long getID() {
return 0;
}
@Override
public void open() throws Exception {
}
@Override
public void close() throws Exception {
}
});
batch.setProcessorChain(p);
QueryStructureByID query = new QueryStructureByID(100215);
batch.setConnection(c.getConnection());
batch.open();
IBatchStatistics stats = batch.process(query);
Assert.assertEquals(1, stats.getRecords(IBatchStatistics.RECORDS_STATS.RECORDS_READ));
Assert.assertEquals(1, stats.getRecords(IBatchStatistics.RECORDS_STATS.RECORDS_PROCESSED));
// C20H20BrP
}
use of ambit2.core.processors.structure.AtomConfigurator in project ambit-mirror by ideaconsult.
the class PKASmartsDescriptorTest method testAcid.
//
@Test
public void testAcid() throws Exception {
SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer a = parser.parseSmiles("O[N+](=O)[O-]");
AtomConfigurator cfg = new AtomConfigurator();
cfg.process(a);
HydrogenAdderProcessor ha = new HydrogenAdderProcessor();
ha.setAddEexplicitHydrogens(true);
a = ha.process(a);
CDKHueckelAromaticityDetector.detectAromaticity(a);
// otherwise getValency() of H atoms returns null (since cdk 1.3.6)
cfg.process(a);
for (int i = 0; i < a.getAtomCount(); i++) {
/*
System.out.print(a.getAtom(i).getSymbol());
System.out.print('\t');
System.out.print(a.getAtom(i).getFlag(CDKConstants.ISAROMATIC));
System.out.print('\t');
System.out.print(String.format("valency %d",a.getAtom(i).getValency()));
System.out.print('\t');
System.out.println(a.getAtom(i).getAtomTypeName());
*/
Assert.assertNotNull(a.getAtom(i).getValency());
}
for (int i = 0; i < a.getAtomCount(); i++) {
Assert.assertNotNull(a.getAtom(i).getValency());
}
for (int i = 0; i < a.getBondCount(); i++) {
Assert.assertNotNull(a.getBond(i).getOrder());
}
DescriptorValue value = pka.calculate(a);
Assert.assertNotNull(value.getValue());
Assert.assertNotNull(((VerboseDescriptorResult) value.getValue()).getExplanation());
}
Aggregations