# MCNPY Exception: Error importing MCNP Deck from file

**URL:** <https://openmc.discourse.group/t/mcnpy-exception-error-importing-mcnp-deck-from-file/4354>\
**Category:** User Support\
**Created:** [June 5, 2024, 7:33pm UTC](https://openmc.discourse.group/t/mcnpy-exception-error-importing-mcnp-deck-from-file/4354 "2024-06-05T19:33:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@ron](https://openmc.discourse.group/u/ron)\
**Post date:** [June 5, 2024, 7:33pm UTC](https://openmc.discourse.group/t/mcnpy-exception-error-importing-mcnp-deck-from-file/4354/1 "2024-06-05T19:33:43Z")

</div>

To all:  
I’m getting this error: Exception: Error importing MCNP Deck from file: my\_file\_name

Note: I am running the script in Anaconda-Navigator Jupyter

I am running the following:  
Windows11 Pro  
WSL2  
Ubuntu 22.04.4 LTS  
Conda version 24.5.0  
Python version 3.11.0 final.0  
solver : libmamba (default)  
virtual packages : \_\_archspec=1=skylake  
\_\_conda=24.5.0=0  
\_\_cuda=12.3=0  
\_\_glibc=2.35=0  
\_\_linux=5.15.146.1=0  
\_\_unix=0=0  
(PySide6. **version** ) 6.7.0  
(PySide6.QtCore. **version** ) 6.7.0  
from PyQt6 import QtCore 6.7.0  
from PyQt5 import QtCore 5.15.8  
numpy.version.version 1.26.4  
matplotlib 3.8.4

I am trying to import and convert an MCNP (LANL) input file to OpenMC, using MCNPY.  
The input file is a simple sphere filled with water, a monoenergetic photon source, and a single tally. I’ve verified that the file will run without errors on MCNP6.3.

This is the script I am using. Note that It contains the MCNP6.3 input file as an output.

import mcnpy as mp  
%matplotlib inline  
from math import pi, sin, cos  
import numpy as np  
import openmc  
import os  
from openmc\_source\_plotter import plot\_source\_position  
home = (os.environ[‘HOME’])

# I tried this both ways. I get the same error

# mcnp\_file\_path = “/home/rlavera/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp”

mcnp\_file\_path = home + “/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp”

# I tried this both ways. Same error.

# file\_path = “/home/rlavera/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp”

file\_path = mcnp\_file\_path  
if os.path.exists(file\_path):  
print(“The file exists!”)  
else:  
print(“The file does not exist.”)

# This is a listing of the simple input file. I verified that it runs with MCNP6.3

!cat “/home/rlavera/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp”

$  
c title simple input for mcnpy conversion  
c  
10 1 -1.0 -10 imp:p=1  
90 0 10 imp:p=0

10 so 50

mode p  
c  
m1 1000. 0.667  
8000. 0.333  
c  
sdef par=2 erg=1  
c  
f2:p 10  
c  
nps 1e6

# I tried this both ways - I get the same error

# deck = mp.Deck.read(“/home/rlavera/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp”)

deck = mp.Deck.read(mcnp\_file\_path)

This is the full error printout:

* * *

Py4JJavaError Traceback (most recent call last)  
File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/metapy/gateway.py:37, in load\_file(filename)  
36 try:  
—\> 37 return gateway.loadFileMcnp(filename)  
38 except:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/java\_gateway.py:1322, in JavaMember. **call** (self, \*args)  
1321 answer = self.gateway\_client.send\_command(command)  
 → 1322 return\_value = get\_return\_value(  
1323 answer, self.gateway\_client, self.target\_id, self.name)  
1325 for temp\_arg in temp\_args:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/protocol.py:326, in get\_return\_value(answer, gateway\_client, target\_id, name)  
325 if answer[1] == REFERENCE\_TYPE:  
 → 326 raise Py4JJavaError(  
327 “An error occurred while calling {0}{1}{2}.\n”.  
328 format(target\_id, “.”, name), value)  
329 else:

Py4JJavaError: An error occurred while calling t.loadFileMcnp.  
: java.lang.NoClassDefFoundError: org/junit/Assert  
at org.eclipse.xtext.testing.validation.ValidationTestHelper.assertNoErrors(ValidationTestHelper.java:186)  
at org.eclipse.xtext.testing.validation.ValidationTestHelper.assertNoErrors(ValidationTestHelper.java:92)  
at EntryPoint.loadFileMcnp(EntryPoint.java:123)  
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.base/java.lang.reflect.Method.invoke(Method.java:566)  
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)  
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)  
at py4j.Gateway.invoke(Gateway.java:282)  
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)  
at py4j.commands.CallCommand.execute(CallCommand.java:79)  
at py4j.GatewayConnection.run(GatewayConnection.java:238)  
at java.base/java.lang.Thread.run(Thread.java:829)  
Caused by: java.lang.ClassNotFoundException: org.junit.Assert  
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)  
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)  
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)  
… 14 more

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)  
File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/metapy/gateway.py:40, in load\_file(filename)  
39 try:  
—\> 40 return gateway.loadFileSerpent(filename)  
41 except:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/java\_gateway.py:1322, in JavaMember. **call** (self, \*args)  
1321 answer = self.gateway\_client.send\_command(command)  
 → 1322 return\_value = get\_return\_value(  
1323 answer, self.gateway\_client, self.target\_id, self.name)  
1325 for temp\_arg in temp\_args:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/protocol.py:326, in get\_return\_value(answer, gateway\_client, target\_id, name)  
325 if answer[1] == REFERENCE\_TYPE:  
 → 326 raise Py4JJavaError(  
327 “An error occurred while calling {0}{1}{2}.\n”.  
328 format(target\_id, “.”, name), value)  
329 else:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/protocol.py:467, in Py4JJavaError. **init** (self, msg, java\_exception)  
465 self.java\_exception = java\_exception  
466 self.exception\_cmd = EXCEPTION\_COMMAND\_NAME + REFERENCE\_TYPE +   
 → 467 java\_exception.\_target\_id + “\n” + END\_COMMAND\_PART

AttributeError: ‘Deck’ object has no attribute ‘\_target\_id’

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)  
File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/metapy/gateway.py:43, in load\_file(filename)  
42 try:  
—\> 43 return gateway.loadFileKeno(filename)  
44 except:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/java\_gateway.py:1322, in JavaMember. **call** (self, \*args)  
1321 answer = self.gateway\_client.send\_command(command)  
 → 1322 return\_value = get\_return\_value(  
1323 answer, self.gateway\_client, self.target\_id, self.name)  
1325 for temp\_arg in temp\_args:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/protocol.py:326, in get\_return\_value(answer, gateway\_client, target\_id, name)  
325 if answer[1] == REFERENCE\_TYPE:  
 → 326 raise Py4JJavaError(  
327 “An error occurred while calling {0}{1}{2}.\n”.  
328 format(target\_id, “.”, name), value)  
329 else:

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/py4j/protocol.py:467, in Py4JJavaError. **init** (self, msg, java\_exception)  
465 self.java\_exception = java\_exception  
466 self.exception\_cmd = EXCEPTION\_COMMAND\_NAME + REFERENCE\_TYPE +   
 → 467 java\_exception.\_target\_id + “\n” + END\_COMMAND\_PART

AttributeError: ‘Deck’ object has no attribute ‘\_target\_id’

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last)  
File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/mcnpy/deck.py:264, in Deck.\_read(self, filename, renumber, preprocess)  
263 filename = preprocessor(filename)  
 → 264 inp = load\_file(filename)  
265 self.\_deck = inp

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/metapy/gateway.py:45, in load\_file(filename)  
44 except:  
—\> 45 raise Exception('PARSING ERROR! for file: ’ + filename)

Exception: PARSING ERROR! for file: /home/rlavera/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp

During handling of the above exception, another exception occurred:

Exception Traceback (most recent call last)  
Cell In[5], line 3  
1 # I tried this both ways - I get the same error  
2 # deck = mp.Deck.read(“/home/rlavera/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp”)  
----\> 3 deck = mp.Deck.read(mcnp\_file\_path)

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/mcnpy/deck.py:255, in Deck.read(cls, filename, renumber, preprocess)  
252 @classmethod  
253 def read(cls, filename=‘inp.mcnp’, renumber=False, preprocess=False):  
254 \_deck = Deck()  
 → 255 \_deck.\_read(filename, renumber, preprocess)  
256 return \_deck

File ~/anaconda3/envs/openmc-env/lib/python3.12/site-packages/mcnpy/deck.py:279, in Deck.\_read(self, filename, renumber, preprocess)  
277 self.\_deck = filename  
278 else:  
 → 279 raise Exception(‘Error importing MCNP Deck from file "’ + filename  
280 + ‘"’)  
281 try:  
282 cells = self.\_deck.cells.cells

Exception: Error importing MCNP Deck from file “/home/rlavera/ipynb/mcnpy-examples/room-conv/mcnpy-conv.mcnp”

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [June 6, 2024, 12:43am UTC](https://openmc.discourse.group/t/mcnpy-exception-error-importing-mcnp-deck-from-file/4354/2 "2024-06-06T00:43:58Z")

</div>

I can’t comment on the mcnpy error, but I would suggest trying out [`openmc_mcnp_adapter`](https://github.com/openmc-dev/openmc_mcnp_adapter/) which has been used to successfully convert very complicated MCNP models.

---

<div class="post-metadata">

**Author:** ![ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@ron](https://openmc.discourse.group/u/ron)\
**Post date:** [June 6, 2024, 3:22pm UTC](https://openmc.discourse.group/t/mcnpy-exception-error-importing-mcnp-deck-from-file/4354/3 "2024-06-06T15:22:03Z")

</div>

Paul

I’d seen this app before. I didn’t install it before bc of some of the stated limitations (SDEF etc.) I may need to take a look at it again.

Thanks  
Ron

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [June 6, 2024, 8:53pm UTC](https://openmc.discourse.group/t/mcnpy-exception-error-importing-mcnp-deck-from-file/4354/4 "2024-06-06T20:53:15Z")

</div>

As far as I’m aware, I don’t think mcnpy will handle `sdef` cards for you either. MCNP and OpenMC don’t have a completely interchangeable system for defining sources (some MCNP features are not available in OpenMC and vice versa). So, the source definition you may have to handle yourself.
