converting Mx scripts

3 replies [Last post]
mspiegel's picture
Offline
Joined: 07/31/2009

There is a python script in the OpenMx package that will convert simple Mx 1.0 scripts into OpenMx scripts. The script is called mxParser.py. It can be found either in the /tools directory (in a binary installation of OpenMx) or in the /inst/tools directory (in a source installation of OpenMx). You will need the python library "ply" to run the script. Use "sudo easy_install ply" to install the ply library on your machine. To use the script from an arbitrary location, modify your $PATH environment variable. Alternatively copy the script to a location in your $PATH (you will need to copy mxAlgebraParser.py as well).

mxParser.py accepts Mx 1.0 scripts on standard input, and returns OpenMx scripts on standard output. If you wish to translate a single Mx Algebra expression, you can run the script mxAlgebraParser.py. Currently mxParser.py recognizes the following commands:

  • #define
  • Title
  • Begin Algebra/End Algebra blocks
  • Begin Matrices/End Matrices blocks
  • Spec
  • Start or Value
mspiegel's picture
Offline
Joined: 07/31/2009
You'll need to redirect

You'll need to redirect standard input and standard output, like so:

./mxParser.py < /Users/tim/Desktop/test.mx > /Users/tim/Desktop/test.R

tbates's picture
Offline
Joined: 07/31/2009
Thanks Michael. Would also

Thanks Michael.

Would also be good to convert mx comments to R comments...
Just match "!.*$"

Run on a script with nothing but comments, it outputs this:

makeLabels <- function(x) { sapply(x, function(y) { paste('var', y, sep = '') })}

model <- mxModel()

Hope it's worth it: I often can't parse Mx out of Mx, let alone into OpenMx :-)

tbates's picture
Offline
Joined: 07/31/2009
hi mike, tried calling this

hi mike,
tried calling this as

./mxParser.py /Users/tim/Desktop/test.mx /Users/tim/Desktop/test.R

mxParser.py just seems to hang. quitting with cntrl-D i got

^D
makeLabels <- function(x) { sapply(x, function(y) { paste('var', y, sep = '') })}

model <- mxModel()

can send you the test.mx file if you wish

previously installed ply OK:
virtue:bin tim$ sudo easy_install ply
Password:
Searching for ply
Reading http://pypi.python.org/simple/ply/
Reading http://www.dabeaz.com/ply/
Best match: ply 3.3
Downloading http://www.dabeaz.com/ply/ply-3.3.tar.gz
Processing ply-3.3.tar.gz
Running ply-3.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-5inZu3/ply-3.3/egg-dist-tmp-EoK2BF
zip_safe flag not set; analyzing archive contents...
Adding ply 3.3 to easy-install.pth file

Installed /Library/Python/2.5/site-packages/ply-3.3-py2.5.egg
Processing dependencies for ply
Finished processing dependencies for ply