Examples (for charge) in moltab.js at CHARGE EXAMPLES
For HETERO END CHARGES, see moltab.js END EXAMPLES

Finding ends of protein chains and their charges.
----------------------------------------
CODE
moltab.js has variables starting with EndsChain[] including EndNGI, EndCGI, etc. etc.


getCharges() is in moltab.js SEMI OBSOLETE?

getChainEnds() in modeldat.js
	if CAO or nucleic P only, does nothing.
	getEndsGIs() uses chainTypeFromName() which returns blank e.g. for heparin 1hpn,
		and sets EndsChainNoType true for use in help.
	getEndsDetails()
	getEndBlocked()
	isProtPoly(), isNucPoly() etc.
	

makeEndsHelp() in help2.js
	uses pdbNoHeader where missing residues would matter.
	does cancelCenteringHidingPreContacts();

showEnd() in help2.js shows a single end close up.
	sets currentEndIndex, currentEndEnd (N or C), currentEnd (Lys32:B)
	or restores them if showEnd is called without parameters
	then calls makeEndSpt()
----------------------------------------
makeEndSpt() scripts.js
  sets currentView

----------------------------------------
STRATEGY FOR FINDING ENDS

N-term
Lowest groupindex for chain=X and protein (GImin).
	Can't use lowest sequence number since rarely not monotonic.
  Can't exclude HETERO b/c terminal residue might be non-standard.
Is it a peptide-bonded part of the chain?
	If yes,
		If there are only 2 peptide-bonded residues, and if both are HETERO, it is a dipeptide
			ligand. HETERO alone is not sufficient, since the end of a >2 chain might be non-std.
		If there are 3 peptide-bonded residues
			it is NTermA (N terminus of chain A) with coordinates.
	If no, try the next higher group-number. And alert: we don't expect this at low end!
Is there a missing residue with sequence number below that of GImin?
    (If sequence number is 1, look for 0 and for -1)
		If there are any missing residues in the chain, and if candidate has an insertion code,
    check for the same sequence number with an insertion code. Next residue might be same
    number, so to look for previous must check both higher and lower letter of alphabet.
  If there is a previos missing residue, no charge.
  If no, verify that its N is not bonded to 2 C's (3 if Pro)
		and if not, show its N as charged.

    If it lacks a main chain N (rare), alert when Charge View requested.

Same approach can be used for C term.

Previous strategy was to look for residues with N having only 1 bond to C (2 for Pro).
This finds the N terms in gaps as well as the end, so then must look for the one with the
lowest sequence nuber (or lowest GI).

------------------------------

METHODS
groupindex=N; hover %G, {...}.groupindex[.min etc.]

Note that GIs differ for PDB-format vs. mmCIF.
  4gxu.pdb chain B C-term GI=499. GI=500 is NAG201 which is at the end of the PDB file.
  4gxu.cif chain B C-term GI=325. NAG201 is GI=4808.
	But {chain=b and protein}.groupindex.max is 499.

Is GIMin covalently part of chain A?
if ({groupindex=GIMin}.O 

AMin = {chain=A and protein and not hetero}.groupindex.min;
select groupindex=AMin

EXISTS: isMissing(chain-name, sequence-number)
-----------------------------------
ENDS Display
set scaleAngstromsPerInch [viewing-distance]

select one terminal residue glu8:a
restrict selected
center selected
zoom 0 # fills screen with currently displayed atoms
zoom/2
select within(5.0,selected) and chain=A
select within(group, selected)
wireframe 0.25
color cpk
select all
backbone 

1d66
select glu8:a
-----------------------------------
TESTS
1d66 {chain=a and protein}.groupindex.min = 62;
{groupindex=62}.resno = 8; {groupindex=62}.group.min = GLU
(group lists GLU for each atom. group.min avoids requiring any specific atom to be present.)

Is GIMin=62 connected via peptide bond to GIMin=63?
groupindex=62 and connected(groupindex=63): selects Glu8.C
If they're connected via peptide bone, they must have the connecting atoms C to N.
Must specify the atoms since e.g. NAG would be connected to ASN.
groupindex=62 and *.c and connected(groupindex=63 and *.n) WORKS
jmolAtomCount returns typeof number.

1d66 {chain=A and protein}.groupindex.max = 118; resno=64;group.min = LEU;
select on groupindex=118 and *.N and connected(1, groupindex=117 and *.c) WORKS
-----------------------------------
If we were using mmCIF could we use the SEQRES to ATOM alignment?
How do you relate sequence numbers to SEQRES? NOT EASY!


CARBOXY end
*.OXT is not required on a terminal residue with coordinates.
The other oxygen is (within(group, *.oxt) and *.o and not sidechain)
Both: *.oxt, (above)

If the OXT is missing (disordered), we are looking for 
DOES NOT WORK
*.o and connected(*.n) is always zero even with numbers in connected.
protein and (*.o and !connected(2, *.n))

also fail: connected(double, *.n), connected(2, unspecified, *.n)
but the NUMBERS are number of bonds to atoms of the specified type,
not the number of sequential bonds thru other atoms to one atom of the
specified type.

aha, _N and connected(2,_H) means NH2 (connected to 2 H's),
an example given in the manual under message, so 

*.o and connected(protein and *.c and !connected(*.n))
IT WORKS

Now the highest sequence number hit is probably the carboxy terminal
residue that has coordinates.

--------------------------
AMINO ends:

THIS WORKS:
protein and *.n and not connected(*.c)

November 2017 for version 2.6:

select nitrogen and protein and backbone and connected(1, carbon)
Now to get the identities of these atoms into javascript:
javascript alert(jmolEvaluate("{selected}.ident.all"))

If the found nitrogen is sequence number 1, I'll assume it is the N terminal.
Or we could check if there are any residues in that chain numbered -1 or 0 that are missing.

If the found nitrogen is sequence number N, see if N-1 in that chain is missing.

Work defining jmol term ntermini will be done in getCharge() in moltab.js

Now I'll make a function isMissing(chainname, seqnum)

---------------------------
If there is not a higher/lower number missing, then it is charged.
If there is a higher/lower number missing, then a charge is missing.
