# DNAPhysics - illegal application state -- command refused

**URL:** <https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852>\
**Category:** Getting Started\
**Created:** [July 19, 2023, 7:48pm UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852 "2023-07-19T19:48:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ErgiP](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/ergip/32/6944_2.png) [@ErgiP](https://geant4-forum.web.cern.ch/u/ErgiP)\
**Post date:** [July 19, 2023, 7:48pm UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852/1 "2023-07-19T19:48:10Z")

</div>

Hi guys,  
I am new in Geant4 and I could use some help.  
I am trying to use Dnaphysics to simulate radiation exposure of 98.85 kev 195Pt in a World Volume of Water but everytime I use for example the command /process/em/addDNARegion World DNA\_opt6 or for example dna/test/addPhysics raddecay I get the error message below:  
illegal application state – command refused:“/process/em/AddDNARegion World DNA\_opt6”  
illegal application state – command refused:" /dna/test/addPhysics raddecay "

I have tried to use the command before and after /run/initialize but I get the same error.

Do you have any ideas why or how I can fix it ?  
Many Thanks in advance  
Ergi

---

<div class="post-metadata">

**Author:** ![bmorgan](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/bmorgan/32/7_2.png) [@bmorgan](https://geant4-forum.web.cern.ch/u/bmorgan)\
**Post date:** [July 20, 2023, 10:18am UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852/2 "2023-07-20T10:18:08Z")

</div>

It’s probable that the initialization is happening in the C++ code before the commands here are executed. Check the code for lines like:

```cpp
runManager->Initialize();

```

That can generally be removed and the initialization deferred to commands, but see the `main()` programs and command macros in the basic examples for the correct structure.

---

<div class="post-metadata">

**Author:** ![ErgiP](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/ergip/32/6944_2.png) [@ErgiP](https://geant4-forum.web.cern.ch/u/ErgiP)\
**Post date:** [July 20, 2023, 7:51pm UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852/3 "2023-07-20T19:51:47Z")

</div>

Thanks for your answer. I searched for a line like this but I don´t seem to find anything that indicates the initialization of the runManager. Below you can find a snippet of my `main()`.

```auto
int main(int argc, char **argv) {

  // Detect interactive mode (if no arguments) and define UI session
  //
  G4UIExecutive* ui = nullptr;
  if ( argc == 1 ) {
    ui = new G4UIExecutive(argc, argv);
  }

  // Construct the default run manager
  auto* runManager = G4RunManagerFactory::CreateRunManager();
  if(argc==3) runManager->SetNumberOfThreads(atoi(argv[2]));
  else runManager->SetNumberOfThreads(2);

  // Set mandatory user initialization classes
  auto physlist = new PhysicsList();
  runManager->SetUserInitialization(new DetectorConstruction(physlist));
  runManager->SetUserInitialization(physlist);

  // User action initialization
  runManager->SetUserInitialization(new ActionInitialization());

```

---

<div class="post-metadata">

**Author:** ![mkelsey](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/mkelsey/32/49_2.png) [@mkelsey](https://geant4-forum.web.cern.ch/u/mkelsey)\
**Post date:** [July 20, 2023, 9:00pm UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852/4 "2023-07-20T21:00:26Z")

</div>

> [@ErgiP](#):
>
> I am trying to use Dnaphysics to simulate radiation exposure of 98.85 kev 195Pt in a World Volume of Water but everytime I use for example the command /process/em/addDNARegion World DNA\_opt6 or for example dna/test/addPhysics raddecay I get the error message below:

Could you post your macro file, and show where you’re inserting the above two commands? You might have a `/run/initialize` command in your macro file, and you’re putting those commands after it, rather than before (or vice versa).

---

<div class="post-metadata">

**Author:** ![ErgiP](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/ergip/32/6944_2.png) [@ErgiP](https://geant4-forum.web.cern.ch/u/ErgiP)\
**Post date:** [July 21, 2023, 8:54am UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852/5 "2023-07-21T08:54:00Z")

</div>

Thanks for your answer!

Sure. Below you can find the macro file, but as I said I tried to put the commands before and after `/run/initialize` but I got the same error.

My macro file:

```auto
/process/em/auger true
/process/em/augerCascade true
/process/em/deexcitationIgnoreCut true 

/process/em/AddDNARegion World DNA_Opt6 

/run/initialize
/dna/test/setMat G4_Water

/gps/particle ion
/gps/ion 78 195 0 98.85 keV

/gps/energy 0 keV

/gps/pos/type Point

/gps/ang/type iso
/gps/pos/centre 0. 0. 0. mm

/run/initialize
/run/beamOn 100000

```

---

<div class="post-metadata">

**Author:** ![mkelsey](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/mkelsey/32/49_2.png) [@mkelsey](https://geant4-forum.web.cern.ch/u/mkelsey)\
**Post date:** [July 21, 2023, 6:56pm UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852/6 "2023-07-21T18:56:19Z")

</div>

I see that you have two occurrences of `/run/initialize` in your macro file. I’m pretty confident that you need the `setMat` command _before_, because that command it changing how the geometry should be built (and /run/initialize triggers building the geometry however it’s configure at that moment).

Conversely, I suspect that the `AddDNARegion` must be _after_ `/run/initialize`, because regions get created or named as part of building the geometry.

---

<div class="post-metadata">

**Author:** ![system](https://geant4-forum.web.cern.ch/uploads/default/original/1X/ce519a43ebdf7ac48a98a03c6ad6eea013b68c46.png) [@system](https://geant4-forum.web.cern.ch/u/system)\
**Post date:** [August 20, 2023, 6:56pm UTC](https://geant4-forum.web.cern.ch/t/dnaphysics-illegal-application-state-command-refused/10852/7 "2023-08-20T18:56:58Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
