CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Numbering Loop Operation

 



marcinek
New User

May 25, 2017, 8:40 AM

Post #1 of 5 (1618 views)
Numbering Loop Operation Can't Post

Dear Community,

Could anybody help me in trivial modification of a simple perl script???

http://chembytes.wdfiles.com/local--files/materials-studio/xtd2xyz.pl

This script converts output from a quantum chemistry program and it produces txt file like this:

Number-of-atoms
blank-line
atom symbol and coordinates-xyz
Number-of-atoms
blank-line
atom symbol and coordinates-xyz

For example (two hydrogen atoms)

2

H 0.1111 0.4444 0.1111
H 0.1211 0.5444 0.0111
2

H 0.4111 0.4144 0.2111
H 0.3211 0.1444 0.1111


I need to modify the script to replace the blank-line by ' i = number-of-structure':

2
i = 1
H 0.1111 0.4444 0.1111
H 0.1211 0.5444 0.0111
2
i = 2
H 0.4111 0.4144 0.2111
H 0.3211 0.1444 0.1111

and so on.

So in principle I just want to add a number of loop made.
Could anyone help me how to do it with perl?

Sorry I am a complete newbie...

Thank you!
Martin


Laurent_R
Veteran / Moderator

May 25, 2017, 10:02 AM

Post #2 of 5 (1612 views)
Re: [marcinek] Numbering Loop Operation [In reply to] Can't Post

I don't know much about chemistry and don't really understand what this program does (especially not knowing the input data).

Maybe it would be easier to reformat the output of this program with another program.


marcinek
New User

May 25, 2017, 10:18 AM

Post #3 of 5 (1608 views)
Re: [Laurent_R] Numbering Loop Operation [In reply to] Can't Post

Dear Laurent, thx for your answer. Well it does not matter. There are thousands of molecular geometries given as xyz cartesian coordinates. This script only translates the format from one to another. I am a dummy in perl, but my only question is how to change this bolded fragment to add the number of geometry printed (the number of the loop which was done) instead of the blank line.
I pressume that it only requires some trivial change in the bolded line?

# loops over the frames
for (my $frame=1; $frame<=$trajectory->NumFrames; ++$frame){
$trajectory->CurrentFrame = $frame;
#write header xyz

$xmolFile->Append(sprintf "%i \n\n", $Natoms);

foreach my $atom (@$atoms) {
# write atom symbol and x-y-z- coordinates
$xmolFile->Append(sprintf "%s %f %f %f \n",$atom->ElementSymbol, $atom->X, $atom->Y, $atom->Z);
}
}


FishMonger
Veteran / Moderator

May 25, 2017, 10:43 AM

Post #4 of 5 (1578 views)
Re: [marcinek] Numbering Loop Operation [In reply to] Can't Post

Try changing it to this:

Code
$xmolFile->Append(sprintf "%i \ni=%d\n", $Natoms, $frame);



marcinek
New User

May 25, 2017, 10:53 AM

Post #5 of 5 (1576 views)
Re: [FishMonger] Numbering Loop Operation [In reply to] Can't Post

Bingo! Million thanks mate!!!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives