Problem of visualization when Geant4-DNA is activated

Geant4 Version: 11.4.0
Operating System: Ubuntu 24.04.3 LTS
Compiler/Version: gcc 13.3.0
CMake Version: 3.28.3


Dear Geant4 users,

I’m new to Geant4. I started with the Geant4-DNA example molcounters-basic which I slightly modified. I would like to validate this changes with visualization but it seems that I’m having trouble getting DNA chemistry and visualization to work together.

With the original molcounter-basic main file I managed to get the chemical part working but not the visualization. I wrote another main file and I managed this time to get the visualization to work but not the chemical part. This is perhaps an obvious problem. But if anyone has any ideas to help me, I would be very grateful !

Original molcounter-basic main file :

#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"

#include "G4DNAChemistryManager.hh"
#include "G4RunManagerFactory.hh"
#include "G4UIExecutive.hh"
#include "G4UImanager.hh"
#include "G4VisExecutive.hh"

int main(int argc, char** argv)
{
  G4UIExecutive* ui = 0;
  if (argc == 1) {
    ui = new G4UIExecutive(argc, argv);
  }

  auto* runManager = G4RunManagerFactory::CreateRunManager();

  // Set mandatory initialization classes
  runManager->SetUserInitialization(new PhysicsList);
  runManager->SetUserInitialization(new DetectorConstruction);
  runManager->SetUserInitialization(new ActionInitialization);

  // get the pointer to the User Interface manager
  auto UI = G4UImanager::GetUIpointer();

  if (argc > 1)  // batch mode
  {
    G4String command = "/control/execute ";
    G4String fileName = argv[1];
    UI->ApplyCommand(command + fileName);
  }
  else  // define visualization and UI terminal for interactive mode
  {
    UI->ApplyCommand("/control/execute simple_sbs.in");
    delete ui;
  }

  delete runManager;
  return 0;
}

I tried ./molcounters_basic vis.mac with the following mac file :

# ==============================
# Visualization macro for DetectorConstruction
# ==============================

# Ouvre la fenêtre OpenGL
/vis/open OGL 800x800-0+0

/run/initialize

# Style général de la géométrie : surface ou wireframe pour tester
/vis/viewer/set/style surface
/vis/viewer/set/autoRefresh true

# Dessine tous les volumes physiques à partir du world
/vis/drawVolume

# Ajouter des axes pour repère (0,0,0) ; longueur 10 um
/vis/scene/add/axes 0 0 0 50 um

# Affiche les trajectoires (smooth) et les accumule à la fin de l'événement
/vis/scene/add/trajectories smooth
/vis/scene/endOfEventAction accumulate

# Couleur par type de particule
/vis/modeling/trajectories/create/drawByParticleID
/vis/modeling/trajectories/drawByParticleID-0/set e- cyan
/vis/modeling/trajectories/drawByParticleID-0/set e_aq magenta
/vis/modeling/trajectories/drawByParticleID-0/set °OH red
/vis/modeling/trajectories/drawByParticleID-0/set H green

# Vue de départ
/vis/viewer/set/viewpointThetaPhi 60 30
/vis/viewer/zoom 2

# Rafraîchissement automatique
/vis/viewer/set/autoRefresh true

Which gave me the error below :

sarah@sarah-Precision-7560:~/Documents/Projet_PEPR/Gate-simulations/Passage-Geant4/basic/build$ ./molcounters_basic vis.mac

**************************************************************
 Geant4 version Name: geant4-11-04 [MT]   (5-December-2025)
  << in Multi-threaded mode >> 
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**************************************************************

***** COMMAND NOT FOUND </vis/open OGL 800x800-0+0> *****

***** Batch is interrupted!! *****

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
Command aborted (100)
Error code : 100
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Hence I tried my own main file :

#include “ActionInitialization.hh”
#include “DetectorConstruction.hh”
#include “PhysicsList.hh”

#include “G4DNAChemistryManager.hh”
#include “G4RunManagerFactory.hh”
#include “G4UIExecutive.hh”
#include “G4UImanager.hh”
#include “G4VisExecutive.hh”

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

// ---- REDIRECTION DE G4cout VERS UN FICHIER ----
std::ofstream out(“molecules.txt”);
G4cout.rdbuf(out.rdbuf());  // tout G4cout ira dans le fichier

G4UIExecutive* ui = 0;
if (argc == 1) {
ui = new G4UIExecutive(argc, argv);
}

auto* runManager = G4RunManagerFactory::CreateRunManager();

// Set mandatory initialization classes
runManager->SetUserInitialization(new PhysicsList);
runManager->SetUserInitialization(new DetectorConstruction);
runManager->SetUserInitialization(new ActionInitialization);

// Initialize visualization
auto visManager = new G4VisExecutive();
visManager->Initialize();

// get the pointer to the User Interface manager
G4UImanager* UI = G4UImanager::GetUIpointer();

if (argc > 1)  // batch mode
{
// Execute the batch macro (argv[1])
const G4String command = “/control/execute “;
const G4String fileName = argv[1];
UI->ApplyCommand(command + fileName);
}
else  // interactive mode
{
// Execute the visualization macro first
UI->ApplyCommand(”/control/execute vis.mac”);

// Start the interactive session
ui->SessionStart();
delete ui;

}

delete runManager;
delete visManager;
return 0;
}

Here the visualization is working but I have no chemistry anymore.

Thank you very much for the help!

Regards,

Sarah

Hi Sarah

It looks like

is missing in the original molcounter-basic main file.

John

Dear John,

Many thanks for your response! I did try this but I got another error :

ERROR: G4VisManager::IsValidView(): Current view is not valid.
ERROR: G4VisManager::PrintInvalidPointers:
  Graphics system is TOOLSSG_X11_GLES but:
  Null scene pointer. Use "/vis/drawVolume" or "/vis/scene/create".
Attributes available for modeling and filtering with
  "/vis/modeling/trajectories/create/drawByAttribute" and
  "/vis/filtering/trajectories/create/attributeFilter" commands:
G4TrajectoriesModel:
  Event ID (EventID): G4int
  Run ID (RunID): G4int
G4SmoothTrajectory:
  Charge (Ch): unit: e+ (G4double)
  Track ID (ID): G4int
  Initial kinetic energy (IKE): G4BestUnit (G4double)
  Initial momentum magnitude (IMag): G4BestUnit (G4double)
  Initial momentum (IMom): G4BestUnit (G4ThreeVector)
  No. of points (NTP): G4int
  PDG Encoding (PDG): G4int
  Parent ID (PID): G4int
  Particle Name (PN): G4String
G4SmoothTrajectoryPoint:
  Auxiliary Point Position (Aux): G4BestUnit (G4ThreeVector)
  Step Position (Pos): G4BestUnit (G4ThreeVector)
WARNING: Trajectory storing has been requested.  This action may be
  reversed with "/tracking/storeTrajectory 0".
WARNING: The vis manager will keep up to 100 events.
  This may use a lot of memory.
  It may be changed with, e.g., "/vis/scene/endOfEventAction accumulate 10".

I think this might be working :

  1. Add to the main.cc file of molcounters-basic
  • the visualization initialization :

auto visManager = new G4VisExecutive();
visManager->Initialize();

  • and ensure that the program remains alive as long as the window is open :

ui->SessionStart();

  1. Modify simple_sbs.in for visualization

molcounters_basic. cc :

int main(int argc, char** argv)
{
  G4UIExecutive* ui = 0;
  if (argc == 1) {
    ui = new G4UIExecutive(argc, argv);
  }

  auto* runManager = G4RunManagerFactory::CreateRunManager();

  runManager->SetUserInitialization(new PhysicsList);
  runManager->SetUserInitialization(new DetectorConstruction);
  runManager->SetUserInitialization(new ActionInitialization);

  auto visManager = new G4VisExecutive();
  visManager->Initialize();

  auto UI = G4UImanager::GetUIpointer();

  if (argc > 1)
  {
    G4String command = "/control/execute ";
    G4String fileName = argv[1];
    UI->ApplyCommand(command + fileName);
  }
  else  
  {
    UI->ApplyCommand("/control/execute simple_sbs.in");
    ui->SessionStart();
    delete ui;
  }

  delete runManager;
  return 0;
}

simple_sbs.in :

/vis/open OGL 800x800-0+0

/run/numberOfThreads 1

/process/chem/TimeStepModel SBS

/run/initialize
/vis/viewer/set/style surface
/vis/viewer/set/autoRefresh true
/vis/drawVolume
/vis/scene/add/axes 0 0 0 50 um
/vis/scene/add/trajectories smooth
/vis/scene/endOfEventAction accumulate
/vis/viewer/set/viewpointThetaPhi 60 30
/vis/viewer/zoom 2
/vis/viewer/set/autoRefresh true

/chem/PrintSpeciesTable

# set all reaction rates to zero (only diffusion)
/chem/reaction/UI

# only transport, no reactions (for speed)

# totally diffusion-controlled (TDC)                | Fix |  reactionRate[dm3/(mol*s)] | TDC (0)
/chem/reaction/add H + H -> H2                      | Fix |  0 | 0
/chem/reaction/add e_aq + H -> H2 + OHm             | Fix |  0 | 0
/chem/reaction/add e_aq + e_aq -> H2 + OHm + OHm    | Fix |  0 | 0
/chem/reaction/add H3Op + OHm -> H2O                | Fix |  0 | 0

# partially diffusion-controlled (PDC)              | Fix |  reactionRate[dm3/(mol*s)] | PDC (1)
/chem/reaction/add OH + H -> H2O                    | Fix |  0 | 1
/chem/reaction/add OH + OH -> H2O2                  | Fix |  0 | 1
/chem/reaction/add e_aq + OH -> OHm                 | Fix |  0 | 1
/chem/reaction/add e_aq + H2O2 -> OHm + OH          | Fix |  0 | 1
/chem/reaction/add e_aq + H3Op -> H + H2O           | Fix |  0 | 1

/chem/reaction/print

/gun/position 0 0 0
/gun/particle e-

/tracking/verbose 0
/scheduler/verbose 0
/scheduler/endTime 0.001 microsecond

/run/verbose 1
/run/printProgress 1

/gun/energy 0.5 keV
/run/beamOn 2

Hi Sarah

Great. Maybe the developer only used it in the batch mode. Maybe you could raise a bug report (see G4 web site). I don’t see any reason why the main program couldn’t handle both interactive and batch, depending on arguments, like many other examples.

John

1 Like

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