From: MD Simulation (mdsimulationgroup_at_gmail.com)
Date: Sat Jul 01 2017 - 20:12:31 CDT

Hello,

I'm trying to write a procedure that will determine the empirical formula
of a fragment:

proc get_empirical_formula {frag_number} {
> set frag_sel [atomselect top "fragment $frag_number"]
> set atoms [$frag_sel get element]
>
> set empirical_formula [dict create]
> foreach atom $atoms {
> if {[dict exists $empirical_formula $atom]} {
> set value [expr {[dict get $empirical_formula $atom] + 1}]
> dict set $empirical_formula $atom $value
> } else {
> dict set $empirical_formula $atom 1
> }
> }
> puts $empirical_formula
> }
>

The idea is that when you get the elements of the frag_sel, you'll get a
list, for instance "C C H H H H H H". I then try to foreach the atom list
and increment a dictionary value. When I try to print the dictionary, all
I get is empty.

Any help would be appreciated. Thanks