1
$\begingroup$
text = " Deg. of freedom     1
 Full point group                 T       NOp  12
 Largest Abelian subgroup         D2      NOp   4
 Largest concise Abelian subgroup D2      NOp   4
                         Standard orientation:                         
 ---------------------------------------------------------------------\

 Center     Atomic      Atomic             Coordinates (Angstroms)
 Number     Number       Type             X           Y           Z
 ---------------------------------------------------------------------\

      1          6           0        0.000000    0.000000    0.\
000000
      2          1           0        0.617765    0.617765    0.\
617765
      3          1           0       -0.617765   \
-0.617765    0.617765
      4          1           0       -0.617765    0.617765   \
-0.617765
      5          1           0        0.617765   -0.617765   \
-0.617765
 ---------------------------------------------------------------------\

 Rotational constants (GHZ):    \
164.2463791    164.2463791    164.2463791
 Standard basis: 6-31G(d) (6D, 7F)
 There are     8 symmetry adapted cartesian basis functions of \
A   symmetry.
 There are     5 symmetry adapted cartesian basis functions of B1  \
symmetry.
 Old FWG=T    [O(C1),4C3(H1)]
 New FWG=TD   [O(C1),4C3(H1)]
 Largest Abelian subgroup         D2      NOp   4
 Largest concise Abelian subgroup D2      NOp   4
                         Standard orientation:                         
 ---------------------------------------------------------------------\

 Center     Atomic      Atomic             Coordinates (Angstroms)
 Number     Number       Type             X           Y           Z
 ---------------------------------------------------------------------\

      1          6           0        0.000000    0.000000    0.\
000000
      2          1           0        0.631339    0.631339    0.\
631339
      3          1           0       -0.631339   \
-0.631339    0.631339
      4          1           0       -0.631339    0.631339   \
-0.631339
      5          1           0        0.631339   -0.631339   \
-0.631339
 ---------------------------------------------------------------------\

 Rotational constants (GHZ):    \
157.2594345    157.2594345    157.2594345";

Here's a text,It is actually generated by the Gaussian09 calculation program. I have captured a small part here, and my goal is to extract the coordinates inside, as shown in the figure below

enter image description here

My idea is to take most of this out and look at it with "Standard orientation:" and "--"

enter image description here

str1 = "Standard orientation:";
str2 = "---------------------------------------------------------------------";

I tried to use the StringCases function to do it but I've done it many times and failed, and now I don't know how to do it, I don't know what match to do to match what I want, I can't think of so far

$\endgroup$
6
  • $\begingroup$ "I tried to use the StringCases function to do it but I've done it many times and failed. " StringCases is the correct function to use. How did you try? Please show us your trial so we can tell you what's wrong. $\endgroup$
    – xzczd
    Commented Apr 17, 2023 at 10:36
  • $\begingroup$ I couldn't find the right matching pattern, the matching failed, so here's what you think $\endgroup$ Commented Apr 17, 2023 at 10:46
  • 1
    $\begingroup$ Hint: Shortest. $\endgroup$
    – xzczd
    Commented Apr 17, 2023 at 10:51
  • 3
    $\begingroup$ FWIW, Import can handle direct importing from Gaussian log files reference.wolfram.com/language/ref/format/GaussianLog.html ; the results go into a Molecule and you can extract the coordinates appropriately (if your goal is to extract coordinates rather than do text file processing) $\endgroup$ Commented Apr 17, 2023 at 18:09
  • 1
    $\begingroup$ "I've used this before. It doesn't do much." I'm not a user of Gaussian, but this is the third time I see similar statement under your question, and the previous two are proven to be wrong. (1. mathematica.stackexchange.com/q/270271/1871 2. mathematica.stackexchange.com/q/275291/1871 ) Are you sure "it doesn't do much"? Can you elaborate a bit so @joshua and us can check if Import really "doesn't do much"? $\endgroup$
    – xzczd
    Commented Apr 22, 2023 at 2:43

2 Answers 2

3
$\begingroup$

We first search the positions of the horizontal dashed lines:

pos = StringPosition[text, 
  "---------------------------------------------------------------------"];

Then we calculate the positions of the start and end of the 2 tables:

pos = {{pos[[2, 2]] + 2, pos[[3, 1]] - 2}, {pos[[5, 2]] + 2, pos[[6, 1]] - 2}};

Then we extract both tables:

text1 = StringTake[text, pos];

Now we import the tables:

tabs = (ImportString[#, "Table"] & /@ text1);

Finally we delete the superfluous port of the tables:

tabs = tabs[[All, All, 4 ;; 6]];

Now tabs contains the 2 tables:

TableForm[tabs[[1]]]
TableForm[tabs[[2]]]

enter image description here

enter image description here

$\endgroup$
3
  • $\begingroup$ That's a good idea $\endgroup$ Commented Apr 17, 2023 at 9:24
  • $\begingroup$ I tried it. I still have a lot of "-- "lines in my file. What should I do if I don't all match to the part that contains" Standard orientation "using this method $\endgroup$ Commented Apr 17, 2023 at 9:29
  • $\begingroup$ If you only want the tables starting with "Standard orientation", simply search positions of substring: "Standard orientation ......... -----------" that starts with "Standard orientation and ends as before". This gives starting positions of tables. The end position is the next ==---..---" line $\endgroup$ Commented Apr 17, 2023 at 11:01
3
$\begingroup$
lines = StringSplit[text, "\n"];

 lines[[10 ;; 14]]  

{   1          6           0        0.000000    0.000000    0.000000,      
    2          1           0        0.617765    0.617765    0.617765,      
    3          1           0       -0.617765   -0.617765    0.617765,      
    4          1           0       -0.617765    0.617765   -0.617765,      
    5          1           0        0.617765   -0.617765   -0.617765}

streams = StringToStream /@ Lines[[10 ;; 14]];

ReadList[# , Number, 6] & /@ streams  

 {  {1,6,0,0.,0.,0.},
    {2,1,0,0.617765,0.617765,0.617765},
    {3,1,0,-0.617765,-0.617765,0.617765},
    {4,1,0,-0.617765,0.617765,-0.617765},
    {5,1,0,0.617765,-0.617765,-0.617765}}
$\endgroup$
2
  • $\begingroup$ I have to know what line it is, so for any output file, I don't know what line it is $\endgroup$ Commented Apr 17, 2023 at 10:34
  • 1
    $\begingroup$ Just do a search for a significant number by (StringPosition[ #, "0.6177" ]&)/@lines $\endgroup$
    – Roland F
    Commented Apr 17, 2023 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.