MCNPY Exception: Error importing MCNP Deck from file

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”

I can’t comment on the mcnpy error, but I would suggest trying out openmc_mcnp_adapter which has been used to successfully convert very complicated MCNP models.

1 Like

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

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.

1 Like