On Sun, Mar 24, 2013 at 3:10 PM, Noel O'Boyle <baoille...@gmail.com> wrote:
> (ccing to list)
>
> Great. Regarding why Al is different is that the atomtyper uses the
> information from atomtyp.txt. For aluminium, the implicit valence is
> set to 3:
> "IMPVAL [#13] 3 # generic Al"
>
> No value is set for Cd.
>
Ah. Makes sense. I sometimes dig around in the code and forget to look in
the data files for OpenBabel.
This leads me to an observation. It seems to me that the concept of
ImplicitValence is just pretty weak. I expected it to be "for this atom,
here's what it does in a normal situation." That is, even when I add five
bonds to a carbon, I expect GetImplicitValence() to return 4. But looking
at the code, it seems to say, "It's four ... but OK if you say it's 5, then
I'll say it's 5." That makes it fairly useless. It's a bit like if I
created a carbon atom and then set its atomic number to 7 and asked what it
was, and was told it was still carbon. It's especially confusing because
the ImplicitValence seems to go up automagically, but not down
automagically.
Oh well, just my two cents. Thanks again for helping me sort this out.
Craig
Thanks,
Craig
>
> - Noel
>
> On 21 March 2013 22:39, Craig James <cja...@emolecules.com> wrote:
> > Thanks, Noel! This is what I needed.
> >
> > I still don't understand why (for example) Aluminum is different from
> > Cadmium. If you run my test program on Cadmium, it works correctly
> without
> > SetImplicitValence(). Still, it's good to have a fix.
> >
> > Craig
> >
> >
> > On Wed, Mar 20, 2013 at 12:54 PM, Noel O'Boyle <baoille...@gmail.com>
> wrote:
> >>
> >> So the desired output is 1,2,3,4,5 instead of 3,3,3,4,5?
> >>
> >> If so, isn't SetImplicitValence what you are looking for?
> >>
> >> >>> mol = pybel.readstring("smi", "[AlH3]").OBMol
> >> >>> mol.DeleteHydrogens()
> >> True
> >> >>> print pybel.Molecule(mol).write("smi")
> >> [AlH3]
> >>
> >> >>> print mol.GetAtom(1).GetImplicitValence() # 3
> >> 3
> >> >>> mol.GetAtom(1).SetImplicitValence(2)
> >> >>> print pybel.Molecule(mol).write("smi")
> >> [AlH2]
> >>
> >> In your example, you were using Begin/EndModify. Unfortunately,
> >> EndModify() unsets ImplicitValencePerceived so that the atom typer is
> >> called again next time a "valence" is requested:
> >> >>> mol.BeginModify()
> >> >>> mol.EndModify()
> >> >>> print pybel.Molecule(mol).write("smi")
> >> [AlH3]
> >>
> >> ...but never fear, we can override this by adding a
> >> mol.SetImplicitValencePerceived() immediately after the EndModify().
> >> The [AlH2] is then retained.
> >>
> >> - Noel
> >>
> >> On 20 March 2013 18:20, Craig James <cja...@emolecules.com> wrote:
> >> > Hi Noel,
> >> >
> >> >
> >> >
> >> > On Tue, Mar 19, 2013 at 3:16 PM, Noel O'Boyle <baoille...@gmail.com>
> >> > wrote:
> >> >>
> >> >> I believe that the key value is the _impval property on an OBAtom,
> >> >> which is assigned by the atomtyper. Can you ask your program to print
> >> >> out the values after the EndModify() using
> atom->GetImplicitValence()?
> >> >
> >> >
> >> > It looks like your analysis is spot on. Here is output of the program
> >> > (not
> >> > the original one, this is much simpler, see below):
> >> >
> >> > molecule starts with 4 atoms.
> >> > delete H, idx = 4
> >> > delete H, idx = 3
> >> > delete H, idx = 2
> >> > molecule now has 1 atoms.
> >> > [AlH3]
> >> > add H, idx = 2, molecule now has 2 atoms, _impval = 3
> >> > [AlH3]
> >> > add H, idx = 3, molecule now has 3 atoms, _impval = 3
> >> > [AlH3]
> >> > add H, idx = 4, molecule now has 4 atoms, _impval = 3
> >> > [AlH3]
> >> > add H, idx = 5, molecule now has 5 atoms, _impval = 4
> >> > [AlH4]
> >> > add H, idx = 6, molecule now has 6 atoms, _impval = 5
> >> > [AlH5]
> >> >
> >> > What's the solution? I can't find any method on the atom or bond
> object
> >> > that will force it to reset its _impval.
> >> >
> >> > Thanks,
> >> > Craig
> >> >
> >> > #include <sstream>
> >> >
> >> > #include <openbabel/babelconfig.h>
> >> > #include <openbabel/mol.h>
> >> > #include <openbabel/obconversion.h>
> >> >
> >> > using namespace std;
> >> > using namespace OpenBabel;
> >> >
> >> > static string test_mol
> >> > (
> >> > "\n"
> >> > " OpenBabel03191316172D\n"
> >> > "\n"
> >> > " 4 3 0 0 0 0 0 0 0 0999 V2000\n"
> >> > " 0.0000 0.0000 0.0000 Al 0 0 0 0 0 0 0 0 0 0 0
> >> > 0\n"
> >> > " 0.0000 0.0000 0.0000 H 0 0 0 0 0 0 0 0 0 0 0
> >> > 0\n"
> >> > " 0.0000 0.0000 0.0000 H 0 0 0 0 0 0 0 0 0 0 0
> >> > 0\n"
> >> > " 0.0000 0.0000 0.0000 H 0 0 0 0 0 0 0 0 0 0 0
> >> > 0\n"
> >> > " 1 2 1 0 0 0 0\n"
> >> > " 1 3 1 0 0 0 0\n"
> >> > " 1 4 1 0 0 0 0\n"
> >> > "M END\n"
> >> > "$$$$\n"
> >> > );
> >> >
> >> > int main(int argc,char **argv)
> >> > {
> >> > OBAtom *atom;
> >> > vector<OBAtom*> delete_h;
> >> > vector<OBAtom*>::iterator ai;
> >> >
> >> > OBMol *pmol = new OBMol;
> >> > OBConversion conv(&cin, &cout);
> >> > conv.SetInAndOutFormats("sdf", "smi");
> >> >
> >> > pmol->Clear();
> >> > conv.ReadString(pmol, test_mol);
> >> > pmol->BeginModify();
> >> >
> >> > cout << "molecule starts with " << pmol->NumAtoms() << " atoms.\n";
> >> > for (atom = pmol->BeginAtom(ai); atom; atom = pmol->NextAtom(ai)) {
> >> > if (atom->GetAtomicNum() == 1)
> >> > delete_h.push_back(atom);
> >> > }
> >> > for (ai = delete_h.end() - 1; ai >= delete_h.begin(); ai--) {
> >> > atom = *ai;
> >> > cout << "delete H, idx = " << atom->GetIdx() << "\n";
> >> > pmol->DeleteAtom(atom);
> >> > }
> >> > cout << "molecule now has " << pmol->NumAtoms() << " atoms.\n";
> >> > pmol->EndModify();
> >> > conv.Write(pmol);
> >> >
> >> > for (int i = 2; i <= 6; i++) {
> >> > pmol->BeginModify();
> >> > atom = pmol->NewAtom(i);
> >> > atom->SetAtomicNum(1);
> >> > pmol->AddBond(1, i, 1);
> >> > pmol->EndModify();
> >> > cout << "add H, idx = " << i <<", molecule now has "
> >> > << pmol->NumAtoms() << " atoms, _impval = "
> >> > << pmol->GetAtom(1)->GetImplicitValence() << "\n";
> >> > conv.Write(pmol);
> >> > }
> >> > }
> >> >
> >
> >
>
------------------------------------------------------------------------------
Own the Future-Intel® Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game
on Steam. $5K grand prize plus 10 genre and skill prizes.
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel