From: Axel Kohlmeyer (
Date: Sat May 22 2010 - 12:46:48 CDT

On Sat, May 22, 2010 at 1:15 PM, Amir Hajiahmadi Farmahini
<> wrote:
> Hi,
> first thanks for the reply.
> Actually, I want to calculate number of specific atoms from surrounding
> molecules around a specific pair of atoms in the molecule of interest to be
> within a specific distance.
> For instance: Suppose in a solution we have carbon dioxide and
> MEA(Ethanolamine)dissolved in water.
> I want to calculate number of nitrogen atoms from MEA which are within 10
> of both oxygens from same CO2 simultaneously. I am going to use RDF and
> coordination number analysis tool implemented in VMD. but first I need to
> explain for VMD how to consider both oxygen from same molecule of CO2 as my
> first selection. Because if I dont confine my selection to the same CO2
> molecule, it will be possible that VMD find some Nitrogens which are within
> 10 of two oxygen atoms each from different CO2 molecules.

well, wouldn't it be better to use with 10 angstrom of the CO2 carbon
as a reference? requiring the nitrogens to be within 10 angstrom of
both oxygens seems quite odd to me.

in any case to get what you want, can be done _much_ easier without
the gofr tool. with measure gofr you compute so many additional things
that you will be wasting a lot of time. you can just use plain atom selections
and then the "num" subcommand.

first you create a list of indices of the oxygen pairs. assuming that they
are consecutive in the file you can do something similar to:

set co2oxsel [atomselect top "resname CO2 and name OC1 OC2"]
set co2oxidx [$co2oxsel list]
set numco2 [expr {[$co2oxsel num] / 2}]

now you loop over the pairs of oxygens and create a selection for each pair
and the atoms you are looking for and then count them.

set counttxt "name N" ; # selection text to pick atoms to count
set countrad 10.0 ; # cutoff radius to count atoms
set sumatom 0
foreach o1 o2 $co2oxidx {
    set sel [atomselect top "(($counttxt) and within $countrad of
index $o1) and (($counttxt) and within $countrad of index $o2)"]
    incr sumatom [$sel num]
    $sel delete
puts "average number of '$counttxt' within $countrad of both CO2
oxygens: [expr {$sumatom*1.0/$numco2}]"

this is off the top of my head, so please check carefully.
it is straightforward to extend this to a whole trajectory.


> Best Regards,
> Amir Farmahini
> Axel Kohlmeyer wrote:
>> On Sat, May 22, 2010 at 10:19 AM, Amir Hajiahmadi Farmahini
>> <> wrote:
>>> Hi,
>>> How can I figure out following problem to be able to generate RDF.
>>> I need underlying selection as my first selection in VMD to generate RDF:
>>> Two or more atoms at them same time have to be selected from "same
>>> molecule"
>>> in "one selection". To bring a very simple example: both Oxygen atoms
>>> from
>>> same molecule of carbon dioxide have to be selected as the first
>>> selection
>>> in RDF to be within a specific distance from Second selection.
>>> Second selection can be any atom from another molecules (Not important
>>> here).
>>> The problem is I was not able to ensure selected atoms are at the same
>>> time
>>> from same molecule.
>> the rdf code knows nothing about molecules. also, your requirements sound
>> very odd. can you please elaborate what property you want to calculate?
>> even though i am not entirely clear about what you want to do, the
>> most promising
>> route seems to be that you do a two step procedure. first extract a
>> set of "subtrajectories"
>> from your original data set that conforms to your first requirement
>> and then compute
>> the rdfs for each of those and average.
>> it may be possible to achieve something similar by setting the user
>> parameter
>> for the oxygen atoms in question to specific numbers corresponding to your
>> requirements, but that can have unexpected side effects.
>> cheers,
>> axel.
>>> Regards,
>>> Amir Farmahini

Dr. Axel Kohlmeyer
Institute for Computational Molecular Science
Temple University, Philadelphia PA, USA.