SimonEnsemble / PorousMaterials.jl

Julia package towards classical molecular modeling of nanoporous materials
GNU General Public License v3.0
51 stars 11 forks source link

custom path when running PorousMaterials.jl #51

Closed mtap-research closed 5 years ago

mtap-research commented 5 years ago

Is there a way for PorousMaterials to FIRST look at the filenames where the program is being executed THEN look at default PorousMaterials.jl data/crystals/ directory? For example, some people would like to run calculations on the folder which contains both script and structure files.

Below is an error message that I received when trying to run one of the example calculations.

using PorousMaterials

framework = Framework("CAXVII_clean.cif")

molecule = Molecule("CO2") set_fractional_coords!(molecule, framework.box)

translate_to!(molecule, [0.0, 1.0, 0.0], framework.box)

rotate!(molecule, framework.box) # let's give it a random orientation

eparams, kvectors, eikar, eikbr, eikcr = setup_Ewald_sum(12.0, framework.box)

energy = electrostatic_potential_energy(framework, molecule, eparams, kvectors, eikar, eikbr, eikcr)

$ julia -p 4 test.jl ERROR: LoadError: SystemError: opening file /Users/ygchung/Desktop/git/CoRE-MOFs/internal/data/crystals/./DOTSOV_clean.cif: No such file or directory Stacktrace: [1] #systemerror#44 at ./error.jl:64 [inlined] [2] systemerror(::String, ::Bool) at ./error.jl:64 [3] open(::String, ::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./iostream.jl:104 [4] open(::String, ::String) at ./iostream.jl:132 [5] #Framework#4(::Bool, ::Float64, ::Bool, ::Bool, ::Type{T} where T, ::String) at /Users/ygchung/Desktop/git/PorousMaterials.jl/src/Crystal.jl:46 [6] PorousMaterials.Framework(::String) at /Users/ygchung/Desktop/git/PorousMaterials.jl/src/Crystal.jl:40 [7] include_from_node1(::String) at ./loading.jl:576 [8] include(::String) at ./sysimg.jl:14 [9] process_options(::Base.JLOptions) at ./client.jl:305 [10] _start() at ./client.jl:371 while loading /Users/ygchung/Desktop/git/CoRE-MOFs/internal/test.jl, in expression starting on line 3

SimonEnsemble commented 5 years ago

That would be dangerous to do for me, as I would trick myself and pull files from the PorousMaterials.jl/data/test directory when I didn't intend! (e.g. if that file were missing in my current directory)

But you can do that by changing src/PorousMaterials.jl to:

PATH_TO_DATA = isdir("data") ? pwd() * "data" : homedir() * "/PorousMaterials.jl/data"

looks for data in present working directory, if not there, assigns directory to PorousMaterials.jl/data. Will only work if you do not change the working directory after you using PorousMaterials.

mtap-research commented 5 years ago

I guess my question was not clear.

I have a CIF file in /Users/ygchung/Desktop/git/CoRE-MOFs/internal/ folder.

It seems like when I run the code as is, it will look for the structures under /Users/ygchung/Desktop/git/CoRE-MOFs/internal/data/crystals/DOTSOV_clean.cif INSTEAD of /Users/ygchung/Desktop/git/CoRE-MOFs/internal/DOTSOV_clean.cif This is likely due to hardcoded path in crystal.jlline 46, which looks under /crystals folder for structure files. Similar convention for molecules.

It appears I would need to create two separate folders (/crystals, /molecules) under the present working directory (PWD) to run PorousMaterials properly. I would also need to have a forcefield files under /molecules. It appears that the code is under the assumption that the User is always working at a specific directory (i.e., PorousMaterials.jl/test/data).

I tried to fix this by making change to the code but this will break the runtests.jl ...

SimonEnsemble commented 5 years ago

Ah yeah, the code assumes there is a folder specified by PATH_TO_DATA with three subfolders: crystals/ forcefields/ molecules

I suppose we could put in the code a global variable const CRYSTALS_FOLDER = "crystals/" that could be changed. Then you could change that to CRYSTALS_FOLDER = "", along with PATH_TO_DATA = "internal" to, when in the folder /Users/ygchung/Desktop/git/CoRE-MOFs, look for the crystals in /Users/ygchung/Desktop/git/CoRE-MOFs/internal.

But yes, then runtests.jl won't work unless you put those crystal structures and input files in /Users/ygchung/Desktop/git/CoRE-MOFs/internal as well. But that's okay since you can just run the tests to make sure they work then change CRYSTALS_FOLDER?

mtap-research commented 5 years ago

Thanks for the comments! It works with your suggestion 👍 However, it would be better if there is a more permanent solution to this in the future! I am sure many simulators would NOT want to create these folders before running simulations. Or this should be explicitly mentioned somewhere in the tutorial.