Skip to content

Replace stoichiometry with a method #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 2, 2016
Merged

Conversation

langner
Copy link

@langner langner commented Aug 1, 2016

This is for cclib#295

@jaimergp
Copy link
Owner

jaimergp commented Aug 1, 2016

I like the proposal! However, my numpy.ndarrays do not feature a .count() method. Which version is yours?

I got this one to work:

import cclib
import numpy
def stoichoimetry(atomnos):
    """Return the stoichemistry of the object."""
    pt = cclib.parser.utils.PeriodicTable()
    formula = []
    unique, counts = numpy.unique(atomnos, return_counts=True)
    counter = {u:c for (u,c) in zip(unique, counts)}
    for ano in sorted(unique, reverse=True):
        count = counter[ano] if counter[ano] > 1 else ''
        formula.append('{}{}'.format(pt.element[ano], count))
    return ''.join(formula)

@jaimergp
Copy link
Owner

jaimergp commented Aug 1, 2016

However, this is not the same as Gaussian's!

For example, I have a Gold complex with this stoichiometry: C17H26AuN2(1+), but this approach outputs AuN2C17H26. While we could add charges, the sorting is non-trivial I think...

@langner
Copy link
Author

langner commented Aug 1, 2016

I like the proposal! However, my numpy.ndarrays do not feature a .count() method. Which version is yours?

You are right, I forgot atomnos is an ndarray. I just commited a fix, but you can also just incorporate your fix.

@langner
Copy link
Author

langner commented Aug 1, 2016

However, this is not the same as Gaussian's!

If you are concerned about the order of elements, we can add some heuristics to the code. Do you have a good reference for how the formula should be formed?

For example, I have a Gold complex with this stoichiometry: C17H26AuN2(1+), but this approach outputs AuN2C17H26. While we could add charges, the sorting is non-trivial I think...

We can add the charge, just use the charge attribute.

@jaimergp jaimergp merged commit 086cc13 into jaimergp:master Aug 2, 2016
jaimergp pushed a commit that referenced this pull request Nov 27, 2017
Slight fix after merging in MOPAC parser
jaimergp pushed a commit that referenced this pull request Feb 2, 2018
Fix order of logfiles in multifile tests
jaimergp pushed a commit that referenced this pull request Aug 1, 2018
Test regressions for number of SCF targets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants