User 221559a7ff
15-08-2013 22:21:23
Hi,
I have a situation in which I'd like to take in a Molecule and return a new one that strictly contains atoms that don't have a residue type. For instance, if I have a Molecule where all but two atoms are from ALA, then I want to get back those two atoms that aren't in the ALA. It is important that bonds be kept intact (I don't want to get back a bunch of atoms that have no bonds).
I tried doing something like this:
public static Molecule getNonResidueAtoms(Molecule m) {
Molecule nonResidues = new Molecule();
for (MolAtom atom : m.getAtomArray()) {
if (atom.getResidueType() == 0) {
nonResidues.add(atom);
}
}
return nonResidues;
}
But the problem with this is that it appears as if I don't get the bonds with it too.
My goal is to eventually do a substructure search based on what's returned by this getNonResidueAtoms method, so I imagine bonds are very important in this case. If there's anything else I need for substucture search to work properly and that isn't covered by this method, I'd like those too.
Thanks!
P.S.: I today discovered how to use the MolSearch#findAll() method and was thoroughly amazed. Thanks to the ChemAxon folks for making such a superb bioinformatics API!
Edit: looking further into the problem, I managed to get a little further by adding in the bonds too. Now my code looks like this:
public static Molecule getNonResidueAtoms(Molecule m) {
Molecule nonResidues = new Molecule();
for (MolAtom atom : m.getAtomArray()) {
if (atom.getResidueType() == 0) {
nonResidues.add(atom);
}
}
for (MolBond bond : m.getAtomArray()) {
if (nonResidues.contains(bond.getAtom1()
&& nonResidues.contains(bond.getAtom2()) {
nonResidues.add(bond);
}
}
return nonResidues;
}
But this too has its issues; the Molecule I pass into this method happens to have a DataSgroup, which appears to be included into the nonResidues file as well. The problem with this is that the DataSgroup refers to an atom that has a residue type, so does not end up in the final molecule. I haven't been able to find methods to strip away DataSgroups from a Molecule. I've attached an example of what I input and what I output.