CCL: XYZ Coordinate Shift (Question and Answers)



 Sent to CCL by: "Wolf-D.Ihlenfeldt" [wdi[]xemistry.com]
 Yet another solution - here is the CACTVS script:
 ---
 set eh [molfile read "oldmol.xyz"]
 lassign [ens get $eh E_XYZEXTENT] xmin xmax ymin ymax zmin zmax
 foreach a [ens atoms $eh] v [ens get $eh A_XYZ] {
         atom set $eh $a A_XYZ [vec subtract $v [list $xmin $ymin $zmin]]
 }
 molfile write "newmol.xyz" $eh
 ------
 Run with the generic interpreter as "csts -f sriptname.tcl" from the
 free
 academic toolkit package (www.xemistry.com/academic).
 Advantages of this solution:
 a) No fixed offset, moves to zero for min. x/y/z coordinate
 b) Works automatically with any file format the toolkit can identify,
 including xyz, pdb and sdf, and will implicitly convert formats (in case
 your input and output formats are different, i.e. xyz->pdb). And you do not
 need to know the intricacies of the file formats, like the awk solution
 below.
 c) Works as batch script without further changes. Extending this to multiple
 files, file name passed as parameter, I/O from/to stdin and stdout,
 multi-record files etc. is trivial
 d) Supported on all major platforms, including Windows, Linux and Solaris.
 W. D. Ihlenfeldt
 Xemistry GmbH
 wdi[*]xemistry.com
 ---
 xemistry gmbh ? Geschäftsführer/Managing Director: Dr. W. D.
 Ihlenfeldt
 Address: Auf den Stieden 8, D-35094 Lahntal, Germany
 HR Marburg B4713 : Ust/VAT ID DE215316329 : DUNS 34-400-1719
 > -----Original Message-----
 > From: owner-chemistry+wdi==xemistry.com[*]ccl.net [mailto:owner-
 > chemistry+wdi==xemistry.com[*]ccl.net] On Behalf Of Mahmoud Korani Abdel-
 > Latif mkkhedr-*-hotmail.com
 > Sent: Wednesday, December 03, 2008 11:35 AM
 > To: Ihlenfeldt, Wolf D
 > Subject: CCL: XYZ Coordinate Shift (Question and Answers)
 >
 >
 > Sent to CCL by: "Mahmoud Korani Abdel-Latif"
 [mkkhedr-x-hotmail.com]
 > Question
 >
 > Dear CCLer's
 > I have the XYZ for certain molecule and I need to shift this XYZ to
 > certain values. What I need is that "I need no negative values in the
 > XYZ" because I need that positive coordinates in other calculations.
 >
 > Is any free program that can do that?
 >
 > Is any script for doing that?
 >
 > Any help to do the above issue will be greatly appreciated.
 >
 > Thanks in advance
 >
 > Mahmoud
 > ---------------------------
 >
 > Answers
 >
 > #! /bin/bash
 >
 > shiftx=100.0
 > shifty=100.0
 > shiftz=100.0
 >
 > cat $* |awk '{printf"%4s %10.5f %10.5f %10.5f\n", $1, $2+$shiftx,
 > $3+$shifty, $4+$shiftz;}'
 >
 > This should shift everything by 100.0 units in every direction.
 >
 >
 > ===================================
 > dr. Marcel Swart
 >
 > ICREA researcher at
 > Institut de Qumica Computacional
 > Universitat de Girona
 >
 > Parc Cientfic i Tecnolgic
 > Edifici Jaume Casademont (despatx A-27)
 > Pic de Peguera 15
 > 17003 Girona
 > Catalunya (Spain)
 >
 > tel
 > +34-972-183240
 > fax
 > +34-972-183241
 > e-mail
 > marcel.swart%%icrea.es
 > marcel.swart%%udg.edu
 > web
 > http://www.icrea.cat/Web/ScientificForm.aspx?key=372
 > http://iqc.udg.edu/~marcel
 >
 >
 > --------------
 >
 > I would ask a crystallographer for help.  They can show you how to
 > graph your xyz coordinates in the unit cell.  If some parts of a
 > particular molecule are outside the unit cell, you could just increase
 > the unit cells dimensions.
 >   Of course crystallographers use fractional coordinates.  That's just
 > x/a, y/b, z/c, etc.  You can easily transform these back to xyz
 > coordinates with BABEL.
 >   Regards, Dave Close
 >
 > ------------------
 >
 > PyMOL does this sort of thing pretty easily:
 >
 > load old_file.pdb
 >
 > alter_state 1, all, (x,y,z)=(x+10,y+2,z+8)
 >
 > save new_file.pdb
 >
 > This capability has been present for years, so the obsolete free builds
 > wills suffice:
 >
 > http://delsci.com/rel/099
 >
 > Cheers,
 > Warren
 > -----------
 >
 > A XYZ file is just a text file with a number on the first line (the
 > number of atoms) a free format line and then a list of atoms with
 > respective XYZ coordinates (4 columns per line).
 > If you take the coordinates from the file, put them in a spreadsheet
 > program (Office, OpenOffice, Gnumeric) and then sum to each element a
 > number (one value for all) big enough to make all of them positive, you
 > get the desired behavior. Then you copy that back into a xyz file and
 > there you go, you have everything positive.
 >
 > This is time consuming but beats learning a new program just to do
 > that.
 >
 > In case you are using Linux, I just cooked up something for you.
 > awk 'a=10 { if (FNR <= 2) print ; else printf("%2s     %11.6f
 %11.6f
 > %11.6f \n",$1,$2+a,$3+a,$4+a) }'   <filename>
 >
 > All of this should be done in one line in the shell (from awk to
 > <filename>).
 > <filename> should be the name of your xyz file.
 > The parameter in beginning (the a=10) is the shift of positions (in
 > this
 > case, 10 Angstrom).
 > Substitute that by any value (integer or not, a decimal number will use
 > a . [9.5 for instance]) and you'll get the corresponding shift. The
 > shift will be done equally in all dimensions.
 >
 > I only tried this in a couple of files and one operating system but it
 > should work on any linux and with any correctly done XYZ file that
 > contains only one structure.
 >
 > Best regards,
 > Daniel Jana
 >
 > -----------
 >
 > You could do this very easily (I routinely do) using a spreadsheet
 > program like Excel. You just have to be careful with tab characters
 > versus spaces.
 >
 > I copy or open the coordinates in Excel, manipulate the values (e.g.
 > add
 > 10 to every x value), then copy the results into a text file. I then
 > open the file with Vi and "1,$s/^I/ /g" removes tabs and replaces
 them
 > with spaces. Note that "^I" is ctrl-V followed by the tab button
 (at
 > least in Windows).
 >
 > Aaron
 >
 > ------------
 >
 > I would hate to overload you with solutions, but Aten
 > (www.projectaten.org, get the Beta version) will also do what you want.
 > For example, from the command line one could do:
 >
 > > aten old.xyz -c 'selectall; translate 10 10 10; savemodel xyz
 > new.xyz;
 > quit'
 >
 > ..to translate all coordinates by 10 Angstroms in each direction. If
 > you
 > want all coordinates moved to the 'lower left-hand corner' you can find
 > the extreme lower-left-hand coordinate first:
 >
 > > aten old.xyz -c 'real minx,miny,minz; atom i; $minx = 1000.0; $miny =
 > 1000.0; $minz = 1000.0; for $i; if $i.rx < $minx; $minx = $i.rx; end;
 > if
 > $i.ry < $miny; $miny = $i.ry; end; if $i.rz < $minz; $minz = $i.rz;
 > end;
 > end; print "Translation is $minx $miny $minz"; selectall;
 translate
 > -$minx -$miny -$minz; savemodel xyz new.xyz; quit'
 >
 > It is also easy with the --batch command to do this for multiple files
 > at
 > once.
 >
 > Hope this helps!
 >
 > ---------
 >
 >
 > Hello, Salam
 >
 > I have seen your question in CCl about XYZ coordination, and I think
 > that you can resolve the problem with Molden, it's a free program
 > http://www.cmbi.ru.nl/molden/molden.html in Linux . But if
 you work
 > with windows you need Xming-6-9-0-31-setup. If you can't procure this
 > program contact me.
 >
 >   Good luck
 > ------------
 >
 > Best regards,
 > Mahmoud
 >
 >
 >
 > -= This is automatically added to each message by the mailing script =-
 > To recover the email address of the author of the message, please
 > change> > > > > > Conferences: http://server.ccl.net/chemistry/announcements/conferences/
 >
 > Search Messages: http://www.ccl.net/htdig  (login: ccl, Password:
 > search)
 > >