Skip to content
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

Close files after opening in Molecule #212

Open
origamimantis opened this issue Apr 1, 2021 · 2 comments
Open

Close files after opening in Molecule #212

origamimantis opened this issue Apr 1, 2021 · 2 comments

Comments

@origamimantis
Copy link

When there are many Molecules being made, eventually an error will be created because there are too many open files.
In my case, I read .xyz files.

Is there a way to close these files?

The error:
Traceback (most recent call last):
File "minimize_ffs.py", line 745, in
File "minimize_ffs.py", line 708, in main
File "minimize_ffs.py", line 474, in min_xtb
File "minimize_ffs.py", line 505, in align
File "/data/homezvol2/zhange5/.conda/envs/zhange5-conda/lib/python3.7/site-packages/forcebalance/molecule.py", line 1264, in init
File "/data/homezvol2/zhange5/.conda/envs/zhange5-conda/lib/python3.7/site-packages/forcebalance/molecule.py", line 2868, in read_xyz
File "/data/homezvol2/zhange5/.conda/envs/zhange5-conda/lib/python3.7/site-packages/forcebalance/molecule.py", line 2889, in read_xyz0
OSError: [Errno 24] Too many open files: 'xtbfull_48.xyz'

@leeping
Copy link
Owner

leeping commented Apr 1, 2021

Strange, I hadn't seen that before. I thought that the file object would close after the loop is finished iterating but maybe not.

Perhaps you could try replacing this line https://github.com/leeping/forcebalance/blob/master/src/molecule.py#L2905 with something like:

with open(fnm) as f:
    for line in f:

Let me know if that resolves the issue.

@origamimantis
Copy link
Author

origamimantis commented Apr 1, 2021

I replaced those lines and it ended up with the same error (which is strange, I thought it would work).
I ended up working around the issue by adapting or importing the functions I needed.

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

No branches or pull requests

2 participants