Hi Geoff,
thank you for the help, it definitely clarifies things, and it explains the
behavior of the old request I sent.
I did see the SetChainPerceived() in multiple places in the C++ code and tried
to use in Python without success.
I've just tried again just to make sure I didn't miss anything, and this is the
summary.
- no matter where HasChainsPerceived() is set, it returns True only until the
EndModify(), which restore it to False (probably expected?);
- calling SetChainPerceived(True) after EndModify() prevents the information
loss; GetResidue() finds the correct information;
- weirdly, even if the perception is properly flagged, the information is
ignored when writing the molecule.
The closest I got it to work is this:
> create new molecule + BeginModify()
> create new atom
> create new residue
> add atom to molecule
> add atom to residue
> EndModify()
> SetChainsPerceived(True)
> WriteFile() # residue information is ignored
Do you have any clues on why is that and how to fix it?
Thanks,
S
p.s. just to make sure, when I look at the documentation, I look here:
http://openbabel.org/dev-api/annotated.shtml
is it what you refer to, as well?
On 10/12/21 10:15, Geoffrey Hutchison wrote:
I've been trying to generate molecules programatically in Python when I found a
buggy behavior.
When you're creating molecules programmatically, you need to make sure you set
the perception flags.
In your case, OBAtom calls:
OBResidue *OBAtom::GetResidue()
{
OBMol *mol = this->GetParent();
if (!mol->HasChainsPerceived())
chainsparser.PerceiveChains(*mol);
return _residue;
}
Since you didn't set OBMol::SetChainsPerceived(true) it's going to throw away
your perception, attempt to find the backbone, etc.
It's in the documentation, but generating molecules programmatically definitely
has some touch points:
Residue information is preserved if the original OBMol is marked as having its
residues perceived. If this is not desired, either call
OBMol::SetChainsPerceived(false) in advance on the original OBMol to avoid
copying the residues (and then reset it afterwards), or else call it on the new
OBMol so that residue information will be reperceived (when requested).
Hope that helps,
-Geoff
--
Stefano Forli, PhD
Associate Professor
Dept. of Integrative Structural
and Computational Biology, MB-112A
Scripps Research
10550 North Torrey Pines Road
La Jolla, CA 92037-1000, USA.
tel: +1 (858)784-2055
email: fo...@scripps.edu
https://forlilab.org
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss