

function findDrawnPointGroupElement(type, map) {
	if (!map)
		map = {};
	var pg = {visible}.pointGroup();
	var items = pg[type];	
	if (items like null) return '0';
	var p = (type == "Cs" ? {200 0 0} : {0 0 200});
	var vz =  point(p, false) - point({0 0 0}, false);
	vz /= vz; // unit vector pointing toward user
	if (!map['nCn']) {
		for (var k in pg) {
			if (k[1] == 'n')
				map[k] = pg[k];
		}
	}
	if (!map[type])
		map[type] = [];
	var m = map[type];
	var ret = '0';
	if (type == 'Ci') {
		m[1] = true;
		return getDrawElement(type);
	}
	for (var i = 1; i <= items.length; i++) {
		var v = items[i];
		var v_dot_vz = abs(v.dot(vz));
		if (v_dot_vz > 0.98)
			ret = i;
		if (ret == i || i > m.length)
			m[i] = (ret == i);
	}
	return (ret > 0 ? getDrawElement(type, ret) : '0');
}


function getDrawElement(type, i) {
	if (type == 'Ci')
		return 'pg0_0_inv';
	if (type == 'Cs')
		return 'pgvp_0_' + i + '*';
	return 'pgva_0_' + (type % -9999) + '_' + i; 
}



/**
$ load $water
H2O

$ x = {*}.pointgroup()
$ print x
{
  "C2"  :
  [
    {0.0 1.0 0.0}
  ]
  "C2_m"  :
  [
    [[-1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,-1.0]]
  ]
  "Cs"  :
  [
    {0.0 0.0 -1.0}
    {1.0 0.0 0.0}
  ]
  "Cs_m"  :
  [
    [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,-1.0]]
    [[-1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]]
  ]
  "center"  :  {0.0 0.2921666666666667 0.0}
  "detail"  :  "# 3 atoms;"
  "distanceTolerance"  :  0.08297788567510692
  "linearTolerance"  :  8.0
  "nAtoms"  :  3
  "nC2"  :  1
  "nCi"  :  0
  "nCn"  :  1
  "nCs"  :  2
  "nElements"  :  3
  "nSn"  :  0
  "nTotal"  :  4
  "name"  :  "C2v"
  "points"  :
  [
    {-0.0 -0.0589 -0.0}
    {-0.811 0.4677 0.0}
    {0.811 0.4677 0.0}
  ]
  "principalAxis"  :  {0.0 1.0 0.0}
 }


$ draw pointgroup
$ draw list
1 id:pg0_0_; model:1.1; vertices:1; polygons:1; visible:true
2 id:pgva_0_c2_1; model:1.1; vertices:2; polygons:1; visible:true; title:C2*
3 id:pgvp_0_1disk; model:1.1; vertices:2; polygons:1; visible:true
4 id:pgvp_0_1ring; model:1.1; vertices:4; polygons:1; visible:true
5 id:pgvp_0_2disk; model:1.1; vertices:2; polygons:1; visible:true
6 id:pgvp_0_2ring; model:1.1; vertices:4; polygons:1; visible:true
$ 

$ show state/draw
   set defaultdrawarrowscale 0.5;
  set drawfontsize 16.0;
  set drawhover false;
  draw delete;
  draw ID "pg0_0_" {0.0 0.2921666666666667 0.0};
  draw ID "pg0_0_" fill noMesh noDots notFrontOnly fullylit;
  color draw opaque [xffd700];
  draw ID "pgva_0_c2_1" diameter 0.05 {0.0 1.4721666666666666 0.0} {0.0 -0.8878333333333333 0.0} "C2*";
  draw ID "pgva_0_c2_1" fill noMesh noDots notFrontOnly fullylit;
  color draw opaque [xff0000];
  draw ID "pgvp_0_1disk" diameter 1.66 CYLINDER {0.0 0.2921666666666667 0.004999999888241291} {0.0 0.2921666666666667 -0.004999999888241291};
  draw ID "pgvp_0_1disk" fill noMesh noDots notFrontOnly fullylit;
  color draw translucent 0.5 [xffff00];
  draw ID "pgvp_0_1ring" scale 1.66 diameter 0.05 ARC {0.0 0.2921666666666667 -1.0} {0.0 0.2921666666666667 1.0} {0.010999999940395355 0.3041666667709748 1.013000000268221} {0.0 360.0 0.5};
  draw ID "pgvp_0_1ring" fill noMesh noDots notFrontOnly fullylit;
  color draw opaque [x0000ff];
  draw ID "pgvp_0_2disk" diameter 1.66 CYLINDER {-0.004999999888241291 0.2921666666666667 0.0} {0.004999999888241291 0.2921666666666667 0.0};
  draw ID "pgvp_0_2disk" fill noMesh noDots notFrontOnly fullylit;
  color draw translucent 0.5 [xffff00];
  draw ID "pgvp_0_2ring" scale 1.66 diameter 0.05 ARC {1.0 0.2921666666666667 0.0} {-1.0 0.2921666666666667 0.0} {-0.9890000000596046 0.3041666667709748 0.013000000268220901} {0.0 360.0 0.5};
  draw ID "pgvp_0_2ring" fill noMesh noDots notFrontOnly fullylit;
  color draw opaque [x0000ff];


