Created
July 3, 2014 09:58
-
-
Save tylerjereddy/8f37ec7b47a00e1f1200 to your computer and use it in GitHub Desktop.
Test #1 for using Python MDAnalysis module within the Julia numerical computing language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if you don't have the Julia PyCall library you can install it with Pkg.add("PyCall") as the first line in this code | |
using PyCall | |
@pyimport MDAnalysis | |
#careful with dotted imports--need simpler module name representation for usage in Julia | |
@pyimport MDAnalysis.tests.datafiles as MDT | |
#can now use MDAnalysis seamlessly and leverage some of the powerful features of the Julia numerical computing language | |
u = MDAnalysis.Universe(MDT.GRO,MDT.XTC) #although this works very naturally, many MDA methods currently require pycall invocation | |
all_atom_selection = pycall(u["selectAtoms"],PyAny,"all") #double quotes only for the "all" string--single quotes are character literals in Julia | |
#the natural call signature doesn't currently work in Julia so using the above workaround: | |
#all_atom_selection = u.selectAtoms("all") #careful! double quotes only because Julia uses single quotes for character literals, NOT strings | |
#Julia isn't finding method fields for a lot of MDAnalysis objects (can we fix this?); for now, pycall will do: | |
all_atom_coordinates = pycall(all_atom_selection["coordinates"],PyAny) | |
coord_type = typeof(all_atom_coordinates) | |
println("Julia type of all system coordinate array: $coord_type") | |
system_centroid = pycall(all_atom_selection["centroid"],PyAny) | |
println("Centroid of test system printed from Julia module: $system_centroid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment