0

I was making a small script in tcl for VMD:

mol load psf run_1/structure.psf xtc run_1/postDocking_wrapped.xtc
set final [atomselect top "not (water or ions or resid 1216)" frame last]

$final writepdb last_frame.pdb
puts "finished!"

quit

I wish i could add the folder I'm working in as a string to last_frame.pdb

like: last_frame_A1234.pdb where A1234 is my current folder. When I try:

set path [file dirname [file normalize [info script] ] ]

it just returns a "."

I have also tried:

set path [file [info script]]

but the result is always the "." rather than A1234F.

If I put:

set path [pwd]

it would give me the full path (with the "/") and writepdb does not accept special characters.

Is there any way to just get the cwd? or from pwd access only to the last folder and use it as a string?

Thank you!

mrcalvin
  • 3,291
  • 12
  • 18

1 Answers1

2

Try: set path [file tail [pwd]]

Colin Macleod
  • 4,222
  • 18
  • 21
  • Sorry to bother you again, but is there a way to access any specific point of the pwd? say I want the second-last part of it, what should I do? – Ludovico Pipitò Mar 09 '22 at 14:46
  • 1
    You could use `file tail [file dirname [pwd]]` or for a more general approach use `file split [pwd]` to convert to a list of names and then use the list commands to get a particular element, e.g. `lindex [file split [pwd]] end-1` - see https://www.tcl-lang.org/man/tcl8.6/TclCmd/file.htm#M35 – Colin Macleod Mar 09 '22 at 14:57