Hydrogen bond length

Hi everyone

I tried to the H-bond length of every H-bond between two sets of atoms, I modified Jason's hbond-life scipt to following:

#!perl

use strict;

use Getopt::Long;

use MaterialsScript qw(:all);

 

# Calculates hydrogen bond lifetime from a trajectory

# Considers only hydrogen bonds between two user defined sets

# User inputs

my \$doc = \$Documents{"Cs-0.5(2).xtd"};

my \$setA = \$doc->UnitCell->Sets("H");

my \$setB = \$doc->UnitCell->Sets("O");

 

# Relabel the atoms so names are unique (and hbond names will be unique)

my \$i=0;

foreach (@{\$doc->UnitCell->Atoms}) { \$i++; \$_->Name = \$_->ElementSymbol . \$i; }

# Label the atoms in sets A and B so they can be identified in the hbond names

foreach (@{\$setA->Atoms}) { \$_->Name .= "_HBSETA"; }

foreach (@{\$setB->Atoms}) { \$_->Name .= "_HBSETB"; }

# Calculate the initial batch of hbonds and store names

my \$trj = \$doc->Trajectory;

\$trj->CurrentFrame = 1;

\$doc->UnitCell->CalculateHBonds;

my \$hbonds = \$doc->UnitCell->HydrogenBonds;

my @hbnames;

foreach (@\$hbonds)

{

my \$a1 = \$_->Atom1->Name;

my \$a2 = \$_->Atom2->Name;

if (( \$a1 =~ /_HBSETA/ and \$a2 =~ /_HBSETB/) or

    ( \$a1 =~ /_HBSETB/ and \$a2 =~ /_HBSETA/))

{

push @hbnames, \$_->Name;

}

}

# H-bond length

my \$i=0;

foreach (@hbnames)

{

\$i++;

\$hbonds->Length;

printf "%4d %30s %8.2f\n", \$i, \$_, \$hbonds;

}

# Discard changes so atom labels are not permanent

\$doc->Discard;

But I got the following error when I debug the script:

There is no function or property named "Length" on type "Collection" at -e line 53.

which is:

\$hbonds->Length;


I'm confused here, I checked the function list, there isn't this one, but Stephen did use this function in his hydrogen bond analysis script.

Does anyone have an idea how to get h-bond length?

Thank you.

Jingjing Bu