TABLE OF CONTENTS
::pwtk::barycenter
SYNOPSIS
proc ::pwtk::barycenter {atmPos {listOfAtoms {}}} {
PURPOSE
Return the barrycenter of atomic positions "atmPos". If the optional 'listOfAtoms' argument is specified, then only the barycenter of the specified atoms is calculated.
ARGUMENTS
- atmPos -- atomic positions (atSym x y z [ix iy iz] per line)
- lisfOfAtoms -- [optional] list of atom indices for which to calculate the barycenter (the first atoms has the index of 1; list of atoms can also have a symbolic compact syntax supported by ::pwtk::parseRangeString). If not specified, the barycenter of all the atoms is calculated.
SOURCE
set atmPos [purifyCoor $atmPos] set nat [getNAtoms $atmPos] # get the list of atoms for which to calculate the barycenter if { $listOfAtoms ne {} } { set sortedList [lsort -integer -increasing [::pwtk::parseRangeString $listOfAtoms $nat]] } else { set sortedList [seq 1 $nat] } # check that indices are in range foreach index $sortedList { ::pwtk::int_in_range1_ $index $nat } # get the listed atoms set atmPosList [split $atmPos \n] foreach ind $sortedList { lappend coorL [lindex $atmPosList $ind-1] } # calculate the barycenter lassign {0. 0. 0.} mx my mz unset nat foreach atom $coorL { lassign $atom atm x y z set mx [expr $mx + $x] set my [expr $my + $y] set mz [expr $mz + $z] incr nat } ifset nat 1; # just in case if $atmPos == {} return [lmap m "$mx $my $mz" {expr $m/double($nat)}] }