Changeset a93896
- Timestamp:
- Aug 30, 2025, 2:41:40 PM (8 weeks ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- 454d7a
- Parents:
- 9928ece
- git-author:
- Frederik Heber <frederik.heber@…> (08/14/25 14:36:30)
- git-committer:
- Frederik Heber <frederik.heber@…> (08/30/25 14:41:40)
- Files:
-
- 4 edited
-
src/Python/PythonScripting.cpp (modified) (4 diffs)
-
src/Python/PythonScripting.hpp (modified) (1 diff)
-
tests/regression/Options/Session/pre/complexwait.py (modified) (1 diff)
-
tests/regression/Options/Session/testsuite-options-load-session-python.at (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Python/PythonScripting.cpp
r9928ece ra93896 37 37 #include "PythonScripting.hpp" 38 38 39 #include <string> 40 39 41 //#include "CodePatterns/MemDebug.hpp" 40 42 … … 58 60 // move all lines with "import" to the beginning 59 61 std::string current_line; 62 std::string moduleName; 60 63 while(std::getline(input,current_line,'\n')){ 61 if (current_line.find("import ") != std::string::npos) 62 buffer_import << current_line << std::endl; 63 else 64 if (current_line.find("import ") != std::string::npos) { 65 if (current_line.find(PYMOLECUILDER_MODULE_NAME) != std::string::npos) { 66 // ignore a PyMoleCuilder import, use the AS however. 67 const size_t lowerCaseAsPos = current_line.find("as"); 68 const size_t upperCaseAsPos = current_line.find("AS"); 69 size_t moduleNameStart = std::string::npos; 70 if (lowerCaseAsPos != std::string::npos) 71 moduleNameStart = lowerCaseAsPos+2+1; 72 if (upperCaseAsPos != std::string::npos) 73 moduleNameStart = upperCaseAsPos+2+1; 74 if (moduleNameStart != std::string::npos) { 75 const size_t moduleNameEnd = current_line.find(" ", moduleNameStart); 76 moduleName = current_line.substr( 77 moduleNameStart, 78 moduleNameEnd == std::string::npos ? moduleNameEnd : moduleNameEnd - moduleNameStart 79 ); 80 ELOG(2, "Ignoring found " << PYMOLECUILDER_MODULE_NAME << " import, but keeping AS name " << moduleName << "."); 81 } else { 82 ELOG(2, "Ignoring found " << PYMOLECUILDER_MODULE_NAME << " import."); 83 } 84 } else { 85 buffer_import << current_line << std::endl; 86 } 87 } else { 64 88 buffer_else << current_line << std::endl; 89 } 65 90 } 66 91 std::string pythonscript_import( std::istreambuf_iterator<char>(buffer_import), … … 71 96 try { 72 97 #ifdef HAVE_PYTHON2 73 PyImport_AppendInittab( "pyMoleCuilder", &initpyMoleCuilder );98 PyImport_AppendInittab( PYMOLECUILDER_MODULE_NAME.c_str(), &initpyMoleCuilder ); 74 99 #else 75 PyImport_AppendInittab( "pyMoleCuilder", &PyInit_pyMoleCuilder );100 PyImport_AppendInittab( PYMOLECUILDER_MODULE_NAME.c_str(), &PyInit_pyMoleCuilder ); 76 101 #endif 77 102 … … 89 114 90 115 boost::python::object molecuilder_module( (boost::python::handle<>(PyImport_ImportModule("pyMoleCuilder"))) ); 91 main_namespace["pyMoleCuilder"] = molecuilder_module; 116 main_namespace[PYMOLECUILDER_MODULE_NAME] = molecuilder_module; 117 if (moduleName.size() > 0) 118 main_namespace[moduleName] = molecuilder_module; 92 119 93 120 std::string enveloped_script("print(\"BEGIN of "+python_scripttitle+":\")\n"); -
src/Python/PythonScripting.hpp
r9928ece ra93896 20 20 bool executePythonScript(const std::string &python_string, const std::string &python_scripttitle); 21 21 22 const std::string PYMOLECUILDER_MODULE_NAME = "pyMoleCuilder"; 23 22 24 #endif /* PYTHONSCRIPTING_HPP_ */ -
tests/regression/Options/Session/pre/complexwait.py
r9928ece ra93896 2 2 from builtins import str 3 3 4 import pyMoleCuilder 4 import pyMoleCuilder as mol 5 5 # ========================== Stored Session BEGIN ========================== 6 6 i=1 7 7 print("wait1 begin") 8 pyMoleCuilder.wait()8 mol.wait() 9 9 i=2 10 10 print("wait1 end") 11 pyMoleCuilder.CommandVerbose(str(i))12 pyMoleCuilder.ParserSetOutputFormats("mpqc tremolo")11 mol.CommandVerbose(str(i)) 12 mol.ParserSetOutputFormats("mpqc tremolo") 13 13 print("wait2 begin") 14 pyMoleCuilder.wait()14 mol.wait() 15 15 i=i+1 16 16 print("wait2 end") 17 pyMoleCuilder.CommandSetRandomNumbersDistribution("uniform_int", "p=1;")18 pyMoleCuilder.WorldChangeBox("20,0,0,20,0,20")19 pyMoleCuilder.AtomAdd("1", "1,1,1")20 pyMoleCuilder.SelectionAtomById("0 0")17 mol.CommandSetRandomNumbersDistribution("uniform_int", "p=1;") 18 mol.WorldChangeBox("20,0,0,20,0,20") 19 mol.AtomAdd("1", "1,1,1") 20 mol.SelectionAtomById("0 0") 21 21 print("wait3 begin") 22 pyMoleCuilder.wait()22 mol.wait() 23 23 i=i+1 24 24 print("wait3 end") 25 pyMoleCuilder.GraphSubgraphDissection()26 pyMoleCuilder.SelectionMoleculeOfAtom()27 pyMoleCuilder.FillRegularGrid("3 3 3", "0.5,0.5,0.5", "1", "0", "0", "0", "0")28 pyMoleCuilder.CommandVersion()25 mol.GraphSubgraphDissection() 26 mol.SelectionMoleculeOfAtom() 27 mol.FillRegularGrid("3 3 3", "0.5,0.5,0.5", "1", "0", "0", "0", "0") 28 mol.CommandVersion() 29 29 print("wait4 begin") 30 pyMoleCuilder.wait()30 mol.wait() 31 31 i=i+1 32 32 print("wait4 end") -
tests/regression/Options/Session/testsuite-options-load-session-python.at
r9928ece ra93896 51 51 file=complexwait.py 52 52 AT_CHECK([../../molecuilder --load-session ${abs_top_srcdir}/tests/regression/Options/Session/pre/$file], 0, [stdout], [ignore]) 53 # NOTE: The output from the python script itself may or may not appear. The embedding has weird 54 # effects, especially with the additional thread for the ActionQueue. Loading a python 55 # script inside the GUI is a miracle to work already. I don't care for now whether the 56 # script itself is also nicely executed. 53 57 AT_CHECK([grep "Setting verbosity from 1 to 2." stdout], 0, [ignore], [ignore]) 54 AT_CHECK([grep "wait1" stdout], 0, [ignore], [ignore]) 55 AT_CHECK([grep "wait2" stdout], 0, [ignore], [ignore]) 56 AT_CHECK([grep "wait3" stdout], 0, [ignore], [ignore]) 57 AT_CHECK([grep "wait4" stdout], 0, [ignore], [ignore]) 58 AT_CHECK([grep "STATUS: Clearing the Adjacency" stdout], 0, [ignore], [ignore]) 59 AT_CHECK([grep "STATUS: Removing all present molecules." stdout], 0, [ignore], [ignore]) 60 AT_CHECK([grep "Calling Action fill-regular-grid" stdout], 0, [ignore], [ignore]) 58 61 59 62 AT_CLEANUP
Note:
See TracChangeset
for help on using the changeset viewer.
