Detecting whether an object is already present!

I have found that several times I want to perform an action conditionally based on the presence of an object. For example, if hydrogen bonds are not present in the structure, I want to calculate hydrogen bonds. Otherwise, I just want to process the hydrogen bonds.

You can use the Perl eval function for this or alternatively you can use the Count function from the Materials Studio API. So far, I have used the Count function like this:

my \\\$hbonds = \\\$doc->UnitCell->HydrogenBonds->Count; if (\\\$hbonds == 0) { \\\$doc->CalculateHBonds; print "Calculating hydrogen bonds \\n"; } else { print "Hydrogen bonds are present\\n"; }


This could be used to detect close contacts, fields, field probes, or any other object that you can count in Materials Studio.

Cheers

Stephen