use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class IsomorphismTests method setUp.
@Before
public void setUp() throws Exception {
// Database
Monomer[] monos = new Monomer[1];
Polymer pepTest = new Polymer(0, "malformin A1", "O=C1NC2C(=O)NC(C(=O)NC(C(=O)NC(C(=O)NC1CSSC2)C(C)CC)CC(C)C)C(C)C", monos);
// Extensions
IAtom a = new Atom("C");
IBond b1 = new Bond(new Atom("S"), a, Order.SINGLE);
this.ext1 = new Extension(b1);
a = new Atom("C");
IAtom a2 = new Atom("C");
IBond b2 = new Bond(a, a2, Order.SINGLE);
this.ext2 = new Extension(b2);
// Mapped blocs
this.mb0 = new MappedChain(pepTest, null, new ArrayList<Integer>(), new ArrayList<Integer>(), new ArrayList<MatchingType>(), new HashMap<Integer, Integer>());
// For blocs Tests
this.bloc = new Chain("S,0,c,0,0,-1,-1;c,0,c,0,0,-1,1");
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class CoveragesJsonLoader method getJSONMatches.
@SuppressWarnings("unchecked")
private JSONObject getJSONMatches(Coverage cov) {
JSONObject graph = new JSONObject();
JSONArray atoms = new JSONArray();
graph.put("atoms", atoms);
JSONArray bonds = new JSONArray();
graph.put("bonds", bonds);
Set<IBond> usedBonds = new HashSet<IBond>();
int matchId = 0;
for (Match match : cov.getUsedMatches()) {
// Atoms
for (int a : match.getAtoms()) {
JSONObject atom = new JSONObject();
// CDK informations
atom.put("cdk_idx", a);
// Atom informations
IAtom ia = cov.getChemicalObject().getMolecule().getAtom(a);
atom.put("name", ia.getSymbol());
atom.put("hydrogens", match.getHydrogensFrom(a));
// Residue informations
atom.put("res", match.getResidue().getId());
atom.put("matchIdx", matchId);
atoms.add(atom);
}
// Bonds
for (int b : match.getBonds()) {
IBond ib = cov.getChemicalObject().getMolecule().getBond(b);
usedBonds.add(ib);
JSONObject bond = new JSONObject();
// CDK informations
bond.put("cdk_idx", b);
// atoms linked
JSONArray linkedAtoms = new JSONArray();
for (IAtom a : ib.atoms()) {
linkedAtoms.add(cov.getChemicalObject().getMolecule().getAtomNumber(a));
}
bond.put("arity", ib.getOrder().numeric());
bond.put("atoms", linkedAtoms);
bond.put("res", match.getResidue().getId());
bonds.add(bond);
}
matchId++;
}
IMolecule mol = cov.getChemicalObject().getMolecule();
for (IBond ib : mol.bonds()) {
if (!usedBonds.contains(ib)) {
JSONObject bond = new JSONObject();
// CDK informations
bond.put("cdk_idx", mol.getBondNumber(ib));
// atoms linked
JSONArray linkedAtoms = new JSONArray();
for (IAtom a : ib.atoms()) {
linkedAtoms.add(mol.getAtomNumber(a));
}
bond.put("arity", ib.getOrder().numeric());
bond.put("atoms", linkedAtoms);
bonds.add(bond);
}
}
return graph;
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class Residue method explicitToImplicitHydrogens.
public void explicitToImplicitHydrogens() {
IMolecule mol = this.getMolecule();
for (IAtom a : mol.atoms()) a.setImplicitHydrogenCount(0);
List<IAtom> toRemove = new ArrayList<>();
for (IAtom a : mol.atoms()) if (a.getAtomTypeName().equals("H")) {
IAtom connected = mol.getConnectedAtomsList(a).get(0);
connected.setImplicitHydrogenCount(connected.getImplicitHydrogenCount() + 1);
toRemove.add(a);
}
for (IAtom a : toRemove) {
mol.removeBond(mol.getConnectedBondsList(a).get(0));
mol.removeAtom(a);
}
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class Residue method getIdxLinks.
public Map<Integer, Rule> getIdxLinks() {
if (this.idxLinkedAtoms == null) {
this.idxLinkedAtoms = new HashMap<>();
for (IAtom a : this.linkedAtoms.keySet()) {
int idx = this.getMolecule().getAtomNumber(a);
this.idxLinkedAtoms.put(idx, this.linkedAtoms.get(a));
}
}
return this.idxLinkedAtoms;
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class Isomorphism method searchFromPreviousMapping.
/**/
public static List<MappedChain> searchFromPreviousMapping(MappedChain mc, Extension ext, int idx1, int idx2, MatchingType type) {
IMolecule mol = mc.getChemObject().getMolecule();
int extIdx = idx1 == -1 ? idx2 : idx1;
List<MappedChain> mappings = new ArrayList<>();
// Connected bonds search
List<IBond> connectedBonds = null;
if (extIdx == -1) {
connectedBonds = new ArrayList<>();
for (IBond bond : mol.bonds()) connectedBonds.add(bond);
} else {
IAtom extAtom = mol.getAtom(mc.getAtomsMapping().get(extIdx));
connectedBonds = mol.getConnectedBondsList(extAtom);
}
for (IBond neighbor : connectedBonds) {
// No need to search bonds already present in mapping.
if (mc.getBondsMapping().contains(mol.getBondNumber(neighbor)))
continue;
List<BondMapping> bms = ext.match(neighbor, type);
for (BondMapping bm : bms) {
// Verification of the compatibility with previous matching
if (idx1 != -1 && mol.getAtomNumber(bm.a0) != mc.getAtomsMapping().get(idx1))
continue;
if (idx2 != -1 && mol.getAtomNumber(bm.a1) != mc.getAtomsMapping().get(idx2))
continue;
// Creation of the new mapping
Chain chain = new Chain(mc.getChain(), ext, idx1, idx2);
List<Integer> atoms = new ArrayList<>(mc.getAtomsMapping());
Map<Integer, Integer> hydrogens = new HashMap<>(mc.getHydrogensMapping());
if (idx1 == -1) {
int an = mol.getAtomNumber(bm.a0);
// To avoid cycles where there is no cycle.
if (mc.getAtomsMapping().contains(an))
continue;
atoms.add(an);
hydrogens.put(an, bm.h0);
}
if (idx2 == -1) {
int an = mol.getAtomNumber(bm.a1);
// To avoid cycles where there is no cycle.
if (mc.getAtomsMapping().contains(an))
continue;
atoms.add(an);
hydrogens.put(an, bm.h1);
}
List<Integer> bonds = new ArrayList<>(mc.getBondsMapping());
bonds.add(mol.getBondNumber(neighbor));
List<MatchingType> matchings = new ArrayList<>(mc.getMatchings());
matchings.add(bm.matchingType);
MappedChain newMc = new MappedChain(mc.getChemObject(), chain, atoms, bonds, matchings, hydrogens);
mappings.add(newMc);
}
}
return mappings;
}
Aggregations