Recycling Corner/Front Selection

From Jmol
Revision as of 18:31, 12 September 2021 by EricMartz (talk | contribs) (Added new function)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

If you "select on" before running this function, then the selected atoms will have halos. This function does not change whether or not selection halos are displayed. This is a Jmol function (not a Javascript function).

function selectFrontPercentage(pct) # pct range: 0 to 100.
{
	# This is a Jmol function (not a Javascript function).
	# This function selects atoms within the specified percentage of the front of the
	# molecule, using the screen Z coordinate atom property "sz".
	# selectFrontPercentage() returns true on success, or false for an invalid parameter.
	# Screen Z depends on the orientation of the molecule.
	# After selection, rotating the molecule does not change the atoms selected, unless
	# selectFrontPercentage() is executed again.

	validRangeMsg = "The valid range is 0 to 100.";

	szmax = {*}.sz.max; // # Rearmost screen Z value.
	szmin = {*}.sz.min; # Low values of screen Z are the front of the view.
	pctf = 0.0 + pct; # cast to float.
	if (pctf == "NaN" || pct.length == 0)
	{
		prompt ('"' + pct + '" is not a number.\n' + validRangeMsg)
		return false;
	}
	if (pctf < 0.0 || pctf >100.0)
	{
		prompt ('"' + pct + '" is out of range.\n' + validRangeMsg)
		return false;
	}
	fxn = pctf/100.0;
	szfront = szmin + ((szmax - szmin) * fxn); # front fraction.
	select sz < szfront;
	return true	
}

Contributors

EricMartz