Running open-Qmin (Python interface)#

Using tools/runHelper.py, you can define command-line parameters through a Python dictionary runHelper.params. These, along with any default parameters you didn’t change, are converted by runHelper.get_runcmd() into a command-line string that calls build/openQmin.out.

The dictionary keys of runHelper.params are the same as the long forms (appearing after the --s) of the command-line flags seen when you run build/openQmin.out --help, with the following exceptions:

  • help itself is not a key in runHelper.params

  • Parameters 'whole_Lx', 'whole_Ly', and 'whole_Lz', which define the system size before subdivision over MPI ranks, override 'Lx', 'Ly', and 'Lz' by default. If you want to use 'Lx', 'Ly', 'Lz' instead (which give the system size on each rank), you can pass do_partition=False to runHelper.get_runcmd().

  • --boxL (or -l) for specifying cubic box size is not used here to avoid ambiguity.

In the example below, we’ll make use of an example boundaryFile that we created in the page on Boundary conditions (Python interface) and the example initialConfigurationFiles that we created in the page on Initialization (Python interface).

Notice that the main open-Qmin directory path, assigned to runHelper.directory, is automatically prepended to the filepaths for imported and exported data. This directory path should be either an absolute path or relative to where you’ll be running the command.

from sys import path
path.append("../tools/")  # <-- replace with your path to runHelper.py

import runHelper

runHelper.directory = "../" # path to open-Qmin main directory
runHelper.mpi_num_processes = 4  # set to 1 for non-MPI run

runHelper.params["boundaryFile"] = "ceiling_and_wavy_floor.txt"
runHelper.params["initialConfigurationFile"] = "my_init_file"

# choose a location and filename-prefix for this run's results
runHelper.params["saveFile"] = "data/my_example_run"
runHelper.params["iterations"] = 500  # max number of minimization timesteps

# system size BEFORE subdivision across MPI ranks:
runHelper.params["whole_Lx"] = 50
runHelper.params["whole_Ly"] = 50
runHelper.params["whole_Lz"] = 50

runcmd = runHelper.get_runcmd()  # generate command-line string
print(runcmd)
mpirun -n 4 ../build/openQmin.out --initializationSwitch 0 --GPU -1 --phaseConstantA -0.172 --phaseConstantB -2.12 --phaseConstantC 1.73 --deltaT 0.0005 --fTarget 1e-12 --iterations 500 --randomSeed -1 --L1 4.64 --L2 0.0 --L3 0.0 --L4 0.0 --L6 0.0 --Lx 25 --Ly 25 --Lz 50 --initialConfigurationFile ../my_init_file --boundaryFile ../ceiling_and_wavy_floor.txt --saveFile ../data/my_example_run --linearSpacedSaving -1 --logSpacedSaving -1 --stride 1 --hFieldX 0 --hFieldY 0 --hFieldZ 0 --hFieldMu0 1 --hFieldChi 1 --hFieldDeltaChi 0.5 --eFieldX 0 --eFieldY 0 --eFieldZ 0 --eFieldEpsilon0 1 --eFieldEpsilon 1 --eFieldDeltaEpsilon 0.5

We can run open-Qmin with these options by any of the following routes:

  • Call runHelper.run(), which executes the result of runHelper.get_runcmd()

  • Copy and paste the string into a terminal

  • Use the runcmd string in a Python script via import os; os.system(runcmd)

  • Run as shell command in a Jupyter notebook with !{runcmd}

runHelper.run()
lattice divisions: {2, 2, 1}
loading state...
loading state...
loading state...
loading state...
reading file with 2 objects
reading boundary type 0 with 5.300000 0.530000 and 26307 entries
reading file with 2 objects
reading boundary type 0 with 5.300000 0.530000 and 26307 entries
reading file with 2 objects
reading boundary type 0 with 5.300000 0.530000 and 26307 entries
reading file with 2 objects
reading boundary type 0 with 5.300000 0.530000 and 26307 entries
object with 26307 sites created
object with 26307 sites created
object with 26307 sites created
object with 26307 sites created
there are now 1 boundary objects known to the configuration... last object had 6577 sites and 1898 surface sites 
reading boundary type 1 with 5.300000 0.530000 and 2500 entries
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 725 surface sites 
there are now 1 boundary objects known to the configuration... last object had 6577 sites and 1898 surface sites 
reading boundary type 1 with 5.300000 0.530000 and 2500 entries
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 725 surface sites 
there are now 1 boundary objects known to the configuration... last object had 6577 sites and 1898 surface sites 
reading boundary type 1 with 5.300000 0.530000 and 2500 entries
there are now 1 boundary objects known to the configuration... last object had 6576 sites and 1895 surface sites 
reading boundary type 1 with 5.300000 0.530000 and 2500 entries
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 725 surface sites 
object with 2500 sites created
there are now 2 boundary objects known to the configuration... last object had 625 sites and 726 surface sites 
fire finished: step 500 max force:3.91e-05 	power: 2.36	 alpha 0.99	 dt 0.045125 	scaling 0.249 
fire finished: step 500 max force:3.91e-05 	power: 2.36	 alpha 0.99	 dt 0.045125 	scaling 0.249 
fire finished: step 500 max force:3.91e-05 	power: 2.36	 alpha 0.99	 dt 0.045125 	scaling 0.249 
fire finished: step 500 max force:3.91e-05 	power: 2.36	 alpha 0.99	 dt 0.045125 	scaling 0.249 
-5237.066075 581.634041 74.221093 0.000000 0.000000
-5236.933788 581.235202 69.360335 0.000000 0.000000
-5236.937263 581.229330 69.360224 0.000000 0.000000
minimized to 3.91031e-05	 E=-0.190661	
minimized to 3.91031e-05	 E=-0.190661	
-5236.936485 581.264815 69.360692 0.000000 0.000000
minimized to 3.91031e-05	 E=-0.190661	
minimized to 3.91031e-05	 E=-0.190661	

Let’s take a look at the result. Here we’re using open-ViewMin, a visualization environment under development for use with open-Qmin. This project is publicly available at open-viewmin/open-viewmin.gitlab.io. Feedback and bug reports will be gratefully received there or at d.a.beller [at] jhu.edu.

Hide code cell content
path.append("../../openviewmin/") # <-- replace with your path to openViewMin

import open_viewmin
import glob

# collect all files from this run
savedFiles = glob.glob("../data/my_example_run*") 
# generate plot off-screen
nplot = open_viewmin.NematicPlot(savedFiles, off_screen=True)
# rotate plane of director glyphs to y-normal
nplot["director_plane"].update(normal=[0,1,0])
# set surface colors
nplot["defects"].set(color=(0, 100, 0))
nplot["boundaries"].set(color=(0, 0, 100));
['../data/my_example_run_x0y1z0.txt', '../data/my_example_run_x1y0z0.txt', '../data/my_example_run_x1y1z0.txt', '../data/my_example_run_x0y0z0.txt'] -> ../data/my_example_run.txt
Imported ../data/my_example_run.txt as frame # 0.
Hide code cell source
# display result in browser

from IPython.display import IFrame
nplot.export_html("./_build/html/py-run-example.html")
# note: delete "_build/html/" in the line above if you run this yourself
IFrame('./py-run-example.html', width=500, height=500)