Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Create and test new attributes for the NBO parser #1251

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 16 commits into from
Aug 29, 2023

Conversation

weronikazak
Copy link
Contributor

This pull request aims to introduce new attributes for the NBO parser, along with corresponding tests for these attributes.

@berquist berquist added this to the v1.8.1 milestone Aug 10, 2023
@berquist berquist added the NBO label Aug 10, 2023
test/testdata Outdated
@@ -309,6 +309,7 @@ SP Psi4 PsiHFSPTest basicPsi4-1.7 dvb_sp_r
SP Psi4 PsiSPTest basicPsi4-1.7 dvb_sp_rks.out
SP QChem GenericSPTest basicQChem5.1 dvb_sp.out
SP QChem GenericSPTest basicQChem5.4 dvb_sp.out
SP NBO NBOSPTest basicNBO7.0 basicORCA5.0/dvb_sp.out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might need to be dvb_sp.nbo.out for just the NBO section.

@berquist berquist marked this pull request as ready for review August 16, 2023 00:06
@@ -160,6 +161,7 @@ class ccData:
"optdone": Attribute(list, 'done', 'optimization'),
"optstatus": Attribute(numpy.ndarray, 'status', 'optimization'),
"polarizabilities": Attribute(list, 'polarizabilities', 'N/A'),
"populations": Attribute(list, 'natural population analysis', 'properties'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'natural population analysis' -> 'population analysis' since this can hold other types of population analyses.
also I think you forgot to change the type from list to dict here

test/testdata Outdated
@@ -309,6 +309,7 @@ SP Psi4 PsiHFSPTest basicPsi4-1.7 dvb_sp_r
SP Psi4 PsiSPTest basicPsi4-1.7 dvb_sp_rks.out
SP QChem GenericSPTest basicQChem5.1 dvb_sp.out
SP QChem GenericSPTest basicQChem5.4 dvb_sp.out
SP NBO NBOSPTest basicNBO7.0/basicORCA5.0 dvb_sp.nbo.out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this in alphabetical order regarding the parser name?

"""Is the number of atoms equal to 3?"""
assert self.data.natom == 3

def testatomcharges(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since only the key name is different from Mulliken, Lowdin, ... in the superclass, can you factor this out into a helper function?

"""Customized restricted single point unittest"""
def testpopulations(self):
assert self.data.populations.keys == list(['nao', 'atom', 'no', 'lang', 'type', 'occupancy', 'energy'])
assert isinstance(self.data.populations['nao'], List[int])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this test is getting run, because

>>> l = [1, 2, 3]
>>> import typing
>>> isinstance(l, typing.List)
True
>>> isinstance(l, typing.List[int])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ejberqu/.pyenv/versions/3.10.11/lib/python3.10/typing.py", line 994, in __instancecheck__
    return self.__subclasscheck__(type(obj))
  File "/Users/ejberqu/.pyenv/versions/3.10.11/lib/python3.10/typing.py", line 997, in __subclasscheck__
    raise TypeError("Subscripted generics cannot be used with"
TypeError: Subscripted generics cannot be used with class and instance checks

typing is also not for runtime type checking, if you wanted to do that over abstract container types it would be from collections.abc, and then checking element types would be a list comprehension over the container.

@@ -159,6 +165,9 @@ def extract(self, inputfile, line):

self.atomcharges["nbo"] = charges

if not hasattr(self, "natom"):
self.set_attribute('natom', len(self.atomcharges["nbo"]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

if not hasattr(self, "populations"):
self.set_attribute('populations', npa_dict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we want self.populations["npa"] = {"nao": ..., ...}?

@berquist
Copy link
Member

Something is still happening with the NBO test not being run: https://github.com/cclib/cclib/actions/runs/5903735648/job/16014303794?pr=1251#step:8:873

@weronikazak
Copy link
Contributor Author

weronikazak commented Aug 18, 2023

Something is still happening with the NBO test not being run: https://github.com/cclib/cclib/actions/runs/5903735648/job/16014303794?pr=1251#step:8:873

Whenever I run the tests, there's a couple of errors popping up

err1

err2

But they appear even after I delete the SP NBO ... record from testdata. I'm running the latest container. Not sure if that's related?

@berquist
Copy link
Member

Sorry I missed this. I don't develop using the container, though I should, but I'd expect CI to catch this,, since CI is always using the latest image. I'll try reproducing this today.

@berquist
Copy link
Member

@weronikazak How are you running the tests? I know we need documentation for this.

@berquist berquist mentioned this pull request Aug 20, 2023
@berquist
Copy link
Member

I can reproduce this with

cd /home/eric/development/forks/python/cclib_pr_review
sudo devcontainer up --workspace-folder .
sudo docker exec -it bold_heisenberg /bin/bash  # using the randomized container name
cd /workspaces/cclib_pr_review
python -m pytest test -k 'not test_method'

because .github/scripts/run_pytest.bash doesn't work anymore. (I don't recall having removed --terse.)

echo $? shows 0, which I think is correct. This is happening in regular CI too, where there's no colored printing (https://github.com/cclib/cclib/actions/runs/5798299575/job/15715727150#step:8:581). It likely comes from #1222. It's definitely misleading and needs to be fixed.

I will see what it takes to get the NBO test to run. It probably has something to do with the nested directory in the testdata entry.

@berquist
Copy link
Member

The stuff to import NBO for testing was missing:

diff --git a/cclib/parser/__init__.py b/cclib/parser/__init__.py
index ab680909..e9e38ac6 100644
--- a/cclib/parser/__init__.py
+++ b/cclib/parser/__init__.py
@@ -25,6 +25,7 @@ from cclib.parser.jaguarparser import Jaguar
 from cclib.parser.molcasparser import Molcas
 from cclib.parser.molproparser import Molpro
 from cclib.parser.mopacparser import MOPAC
+from cclib.parser.nboparser import NBO
 from cclib.parser.nwchemparser import NWChem
 from cclib.parser.orcaparser import ORCA
 from cclib.parser.psi3parser import Psi3
diff --git a/test/data/testSP.py b/test/data/testSP.py
index f198ef2c..d42f4566 100644
--- a/test/data/testSP.py
+++ b/test/data/testSP.py
@@ -604,10 +604,6 @@ class NBOSPTest(GenericSPTest):
     def testnatom(self):
         """Is the number of atoms equal to 3?"""
         assert self.data.natom == 3
-
-    def testatomchargesnbo(self):
-        """Are atomic charges consistent with natom?"""
-        self.testatomcharges()

 class TurbomoleSPTest(GenericSPTest):
     """Customized restricted single point KS unittest"""
diff --git a/test/test_data.py b/test/test_data.py
index 3164c31e..a7c0acf5 100644
--- a/test/test_data.py
+++ b/test/test_data.py
@@ -27,7 +27,7 @@ sys.path.insert(1, os.path.join(__filedir__, 'data'))

 parser_names = [
     "ADF", "DALTON", "FChk", "GAMESS", "GAMESSDAT", "GAMESSUK", "Gaussian", "Jaguar",
-     "Molpro", "Molcas", "MOPAC", "NWChem", "ORCA", "Psi4", "QChem",
+     "Molpro", "Molcas", "MOPAC", "NBO", "NWChem", "ORCA", "Psi4", "QChem",
     "Turbomole",
 ]
 all_parsers = {name: getattr(cclib.parser, name) for name in parser_names}

I think you should replace testatomchargesnbo with a test that ensures "nbo" is a key in atomcharges.

@weronikazak
Copy link
Contributor Author

@weronikazak How are you running the tests? I know we need documentation for this.

I use python -m pytest -v -s --terse test -k "not test_method". Other than the errors above, it seems to be working fine for me

@berquist
Copy link
Member

I will fix the line ending problem so you don't have to.

@berquist
Copy link
Member

The merge commit didn't contain any proper changes, so this branch is up-to-date with master.

For the tests, I'm getting

test/test_data.py:116: in getdatafile
    data = logfile.parse()
cclib/parser/logfileparser.py:216: in parse
    data = self.datatype(attributes=self.__dict__)
cclib/parser/data.py:221: in __init__
    self.setattributes(attributes)
cclib/parser/data.py:318: in setattributes
    self.arrayify()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <cclib.parser.data.ccData object at 0x7f34935d9d50>

    def arrayify(self) -> None:
        """Converts appropriate attributes to arrays or lists/dicts of arrays."""

        attrlist = [k for k in self._attrlist if hasattr(self, k)]
        for k in attrlist:
            v = self._attributes[k].type
            precision = 'd'
            if k in self._intarrays:
                precision = 'i'
            if v == numpy.ndarray:
                setattr(self, k, numpy.array(getattr(self, k), precision))
            elif v == list and k in self._listsofarrays:
                setattr(self, k, [numpy.array(x, precision) for x in getattr(self, k)])
            elif v == dict and k in self._dictsofarrays:
                items = getattr(self, k).items()
                pairs = [(key, numpy.array(val, precision)) for key, val in items]
                setattr(self, k, dict(pairs))
>           elif v == dict and k in self._dictsofdicts:
E           AttributeError: 'ccData' object has no attribute '_dictsofdicts'. Did you mean: '_dictsofarrays'?

@berquist berquist linked an issue Aug 28, 2023 that may be closed by this pull request
@weronikazak weronikazak force-pushed the NBO-parser branch 2 times, most recently from 0e75bb0 to 514f936 Compare August 28, 2023 18:36
@weronikazak
Copy link
Contributor Author

weronikazak commented Aug 28, 2023

I will fix the line ending problem so you don't have to.

Sorry, I just saw this comment!
I've tried to fix it in the meantime, and locally it seems to be working okay. Let's see if it passes the tests

@weronikazak
Copy link
Contributor Author

Hmm, it doesn't work 😕
Do you think it's rebasing issues?

@berquist
Copy link
Member

Yes. The problem is that you've combined Git operations (checkout, add, commit, or some combination, I'm not sure) on Windows with some inside the container. (The following explanation isn't great and might not be fully correct without reproducing it myself but should be enough.)

When you clone a repo on an operating system, Git by default will transparently not mess up line endings in files if they're different on the remote (GitHub) from your local copy. The settings for how this works are different on Windows than on Linux and macOS. If you have the same checkout that crosses operating systems (like the container bind mount), you can violate these settings. The result is that you can inadvertently change the line endings of every file in the repo.

The best explanation I've found for how to understand this and fix it for Git is https://kuantingchen04.github.io/line-endings/. I have core.autocrlf=input in ~/.gitconfig since I use Linux and sometimes macOS. It sounds like you would want true instead of input if you plan on doing all Git operations Windows-side, though when everything is done in the container (VSC Git extension or terminal) I wouldn't have expected this. If you rebase everything from entirely within the container, the problem might go away?

@berquist
Copy link
Member

I can see how this works on Windows but it will be a few more hours.

@berquist
Copy link
Member

I checked out a copy of the repository using the official Git for Windows into my Windows (not WSL) home directory. I don't have a ~/.gitconfig for this. If I open this directory in VSC, it shows no changes; the default is to check out as native line endings (CRLF). Modifying lines As soon as I start the Dev Container,
checkout_windows
because Git for Windows checked everything out as CRLF but most files in the repo are entirely LF line endings, and this is running Git from inside the container.

If I set git config --global core.autocrlf=true and then redo everything, the problem remains because the local checkout is still CRLF.

The solution to stop this from happening again is to only clone using WSL so that line endings are consistent with the Dev Container (both are Linux).

The immediate fix is to do the clone in WSL and try rebasing your branch against master from within WSL.

Copy link
Member

@berquist berquist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got rid of the merge commit and the last commit which didn't do what was expected with the line endings. Also the second ~half of commits looked to be the reverse of the first half, so dropped those in the interactive rebase.

@berquist berquist requested a review from shivupa August 29, 2023 21:05
Copy link
Member

@shivupa shivupa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove rtd fully now that github actions builds docs. ill open a separate issue for that

@shivupa shivupa merged commit 99c8af6 into cclib:master Aug 29, 2023
@weronikazak
Copy link
Contributor Author

I got rid of the merge commit and the last commit which didn't do what was expected with the line endings. Also the second ~half of commits looked to be the reverse of the first half, so dropped those in the interactive rebase.

Thank you!

@berquist berquist mentioned this pull request Mar 11, 2024
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New parser request: NBO
3 participants