use of model.ChemicalObject in project Smiles2Monomers by yoann-dufresne.
the class Isomorphism method searchFromPreviousMapping.
/**
* Search a list of mapped blocs from a smaller mapped bloc
* @param mb Initial mapped bloc
* @param ext Extension to the previous mapped bloc
* @return New mapped blocs.
*/
public static List<MappedChain> searchFromPreviousMapping(MappedChain mb, Extension ext, MatchingType type) {
List<MappedChain> mbs = new ArrayList<>();
ChemicalObject co = mb.getChemObject();
IMolecule mol = co.getMolecule();
List<Integer> neighbors = mb.getNeighborsBonds(mol);
// Create a new bloc for each neighbor
for (int idx : neighbors) {
// Create bloc
IBond nb = mol.getBond(idx);
List<BondMapping> matchings = ext.match(nb, type);
for (BondMapping bm : matchings) {
int atomIdx0 = mol.getAtomNumber(bm.a0);
int atomIdx1 = mol.getAtomNumber(bm.a1);
int blocPosition0 = mb.getMappingIdx(atomIdx0);
int blocPosition1 = mb.getMappingIdx(atomIdx1);
int hydrogen0 = bm.h0;
int hydrogen1 = bm.h1;
Chain bloc = new Chain(mb.getChain(), ext, blocPosition0, blocPosition1);
List<Integer> atoms = new ArrayList<>(mb.getAtomsMapping());
if (blocPosition0 == -1)
atoms.add(atomIdx0);
if (blocPosition1 == -1)
atoms.add(atomIdx1);
List<Integer> bonds = new ArrayList<>(mb.getBondsMapping());
bonds.add(mol.getBondNumber(nb));
List<MatchingType> matchingTypes = new ArrayList<>(mb.getMatchings());
matchingTypes.add(bm.matchingType);
Map<Integer, Integer> hydrogens = new HashMap<>(mb.getHydrogensMapping());
if (!hydrogens.containsKey(atomIdx0) || hydrogens.get(atomIdx0) <= hydrogen0)
hydrogens.put(atomIdx0, hydrogen0);
if (!hydrogens.containsKey(atomIdx1) || hydrogens.get(atomIdx1) <= hydrogen1)
hydrogens.put(atomIdx1, hydrogen1);
MappedChain newMb = new MappedChain(co, bloc, atoms, bonds, matchingTypes, hydrogens);
if (!mbs.contains(newMb))
mbs.add(newMb);
}
}
return mbs;
}
use of model.ChemicalObject in project Smiles2Monomers by yoann-dufresne.
the class ChainLearning method createBlocsFromPrevious.
private List<MappedChain> createBlocsFromPrevious(List<MappedChain> prevMbs) {
List<MappedChain> nextMbs = new ArrayList<>();
for (MappedChain mb : prevMbs) {
ChemicalObject co = mb.getChemObject();
IMolecule mol = co.getMolecule();
List<Integer> neighbors = mb.getNeighborsBonds(mol);
// Create a new bloc for each neighbor
for (int idx : neighbors) {
// Create bloc
IBond nb = mol.getBond(idx);
Extension ext = new Extension(nb);
// Extension.setAromacityTest(false);
List<MappedChain> newMbs = Isomorphism.searchFromPreviousMapping(mb, ext, MatchingType.EXACT);
// Extension.setAromacityTest(true);
nextMbs.addAll(newMbs);
}
}
return nextMbs;
}
use of model.ChemicalObject in project Smiles2Monomers by yoann-dufresne.
the class CoveragesJsonLoader method objectFromJson.
@Override
protected Coverage objectFromJson(JSONObject obj) {
// TODO : Create new parser with the files created by the new output functions
System.err.println("From classe '" + CoveragesJsonLoader.class.getName() + "' method 'objectFromJson':");
System.err.println("This is deprecated ! You will have some problems with recent json files !");
ChemicalObject co = null;
try {
co = this.db.getObject("" + ((Number) obj.get("peptide")).intValue());
} catch (NullPointerException e) {
System.err.println(e.getMessage());
System.err.println("Maybe coverage json and molecule json don't match");
System.exit(2);
}
Coverage cov = new Coverage(co);
JSONArray array = (JSONArray) obj.get("matches");
for (Object o : array) {
JSONObject jso = (JSONObject) o;
Residue res = null;
try {
res = this.residues.getObject("" + ((Number) jso.get("residue")).intValue());
} catch (NullPointerException e) {
e.printStackTrace();
}
JSONObject jMatch = (JSONObject) jso.get("match");
Match match = new Match(res);
JSONArray atoms = (JSONArray) jMatch.get("atoms");
for (Object atObj : atoms) {
JSONObject atom = (JSONObject) atObj;
int idx = ((Number) atom.get("a")).intValue();
match.addAtom(idx);
match.addHydrogens(idx, ((Number) atom.get("h")).intValue());
}
JSONArray bonds = (JSONArray) jMatch.get("bonds");
for (Object boObj : bonds) {
int bond = ((Number) boObj).intValue();
match.addBond(bond);
}
cov.addMatch(match);
}
cov.calculateGreedyCoverage();
return cov;
}
Aggregations