If you’re using Python, I’d recommend using collections.Counter (part of
the standard lib). It’s better than rolling out your own parser.

In [1]: from rdkit import Chem
In [2]: mol = Chem.AddHs(Chem.MolFromSmiles('C(=O)O'))
In [3]: from collections import Counter
In [4]: c = Counter(atom.GetSymbol() for atom in mol.GetAtoms())
In [5]: c
Out[5]: Counter({'H': 2, 'O': 2, 'C': 1})

Counter acts like a dict + some extra methods, and can be converted to a
plain dict with d = dict(c).

Pat
​


On Fri, Jun 13, 2014 at 6:34 AM, Greg Landrum <greg.land...@gmail.com>
wrote:

> if you want the formula as dictionary of counts instead of a string, you
> can either parse the string or write a separate calculator.
> Andrew Dalke posted one a while ago:
> http://sourceforge.net/p/rdkit/mailman/message/21653212/
>
> -greg
>
>
>
> On Fri, Jun 13, 2014 at 4:49 AM, Alexey Chernobrovkin <
> chernobrov...@gmail.com> wrote:
>
>> Thanks, Adrian.
>>
>> Won’t I reinvent the wheel if I’ll parse the formula to get a dict
>> (element->count)?
>>
>> On Jun 13, 2014, at 10:43 , Adrian Jasiński <jasinski.adr...@gmail.com>
>> wrote:
>>
>>
>> http://www.rdkit.org/Python_Docs/rdkit.Chem.rdMolDescriptors-module.html#CalcMolFormula
>>
>>         from rdkit.Chem.rdMolDescriptors import CalcMolFormula
>>         formula = CalcMolFormula(Chem.MolFromSmiles("CCCOC"))
>>
>> pozdrawiam
>> Adrian
>>
>>
>> 2014-06-13 10:20 GMT+02:00 Alexey Chernobrovkin <chernobrov...@gmail.com>
>> :
>>
>>> Hi all,
>>>
>>> Sorry for stupid question… But what is the simplest way to get chemical
>>> formula of a molecule using rdkit?
>>>
>>> Cheers,
>>> Alex
>>>
>>> ------------------------------------------------------------------------------
>>> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
>>> Find What Matters Most in Your Big Data with HPCC Systems
>>> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
>>> Leverages Graph Analysis for Fast Processing & Easy Data Exploration
>>> http://p.sf.net/sfu/hpccsystems
>>> _______________________________________________
>>> Rdkit-discuss mailing list
>>> Rdkit-discuss@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
>> Find What Matters Most in Your Big Data with HPCC Systems
>> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
>> Leverages Graph Analysis for Fast Processing & Easy Data Exploration
>> http://p.sf.net/sfu/hpccsystems
>> _______________________________________________
>> Rdkit-discuss mailing list
>> Rdkit-discuss@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>>
>>
>
>
> ------------------------------------------------------------------------------
> HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
> Find What Matters Most in Your Big Data with HPCC Systems
> Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
> Leverages Graph Analysis for Fast Processing & Easy Data Exploration
> http://p.sf.net/sfu/hpccsystems
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to