Message Boards Message Boards

1
|
8866 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Searching with StringCases in ChemicalData

Posted 9 years ago

Hello, I am trying to find certain chemical compounds in “Chemical Data”’ who contain certain substrings. I have found a solution but I am not very satisfied with. Is there a better one ? See attach.

Thank you for your time,

Chiel Geeraert

Attachments:
POSTED BY: Chiel Geeraert
3 Replies
Posted 9 years ago

Thank you both. I was not very clear why I was not satisfied with my own solution . In my solution I had al those empty "{}". But as you showed in your solution with a simple 'Flatten" command I got rid of them. Something I overlooked completely.

Best regards Chiel Geeraert

POSTED BY: Chiel Geeraert

I am not sure what version of Mathematica are you using. I am using latest 10.1 version. It returns ChemicalData as list of so called Entity (orange things below).

chedat = ChemicalData[];
chedat[[;; 5]]

enter image description here

This is why below I use CommonName. Besides that, using pattern ___ or BlankNullSequence instead of __ or BlankSequence will also give you the "border" cases when hydrogen has no characters on the right or / and left.

Flatten[StringCases[CommonName[chedat], __ ~~ "hydro" ~~ __ ]] // Length

4274

Flatten[StringCases[CommonName[chedat], ___ ~~ "hydro" ~~ ___ ]] // Length

4374

POSTED BY: Vitaliy Kaurov

You have given a perfectly good solution. I don't see how it can be significantly improved.

POSTED BY: S M Blinder
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract