r/pythonhelp • • Nov 16 '20

Counting atoms with python

I wish to calculate partial charge in complex (im a chemist)

So my problem is that i have a list : ['H2O','OH','COOH'] for exemple

I need to know the number of occurrences of all atoms. So here 4 for H. My problem is that the number of occurrences is the number of occurrences of the letter describing the atom if no stoechiométric coefficient, and else the number of that coefficient, but the number could appear or not at any place except at position 0.

I don't see how can i make this with python and now i'm quite confused.

Do you have any tips for me?

Thanks for your help and time!

3 Upvotes

15 comments sorted by

View all comments

Show parent comments

1

u/heirna Nov 16 '20

I'm still processing your code, this extra fonctionality is not trivial to me, and will not be verry useful in the code since this model is verry simple and cannot handle a lot of atoms, i think i will just remap Cu as X for instance to spare me extra headeach.

2

u/CrayonConstantinople Nov 17 '20

I have edited my code above to be easier to understand, hope it helps :)

2

u/heirna Nov 17 '20

ion for me to add if you required it.

The fact that you are struggling to understand my code is what had concerned me when I was writing it, I have not made it clear. I was trying to get you your solution, at the expense of writing clear and concise code.

If it would be helpful, I'm happy to quickly rewrite it to make whats happening clearer.

Oh not at all, i'm just quite a beginner in code so this is normal, thanks for that edit !

1

u/heirna Nov 17 '20

our code, this extra fonctionality is not trivial to me, and will not be verry useful in the code si

And my code is such a mess compared to yours