chem.Molfile.parsePropertyLines = function()

in gsoc2022/seagrid-rich-client/molview/src/js/chem/chem/molfile.js [518:678]


chem.Molfile.parsePropertyLines = function (ctab, ctabLines, shift, end, sGroups, rLogic)
{
	var mf = chem.Molfile;
	var props = new util.Map();
	while(shift < end)
	{
		var line = ctabLines[shift];
		if(line.charAt(0) == 'A')
		{
			if(!props.get('label'))
				props.set('label', new util.Map());
			props.get('label').set(mf.parseDecimalInt(line.slice(3, 6)) - 1, ctabLines[++shift]);
		}
		else if(line.charAt(0) == 'M')
		{
			var type = line.slice(3, 6);
			var propertyData = line.slice(6);
			if(type == "END")
			{
				break;
			}
			else if(type == "CHG")
			{
				if(!props.get('charge'))
					props.set('charge', new util.Map());
				props.get('charge').update(mf.readKeyValuePairs(propertyData));
			}
			else if(type == "RAD")
			{
				if(!props.get('radical'))
					props.set('radical', new util.Map());
				props.get('radical').update(mf.readKeyValuePairs(propertyData));
			}
			else if(type == "ISO")
			{
				if(!props.get('isotope'))
					props.set('isotope', new util.Map());
				props.get('isotope').update(mf.readKeyValuePairs(propertyData));
			}
			else if(type == "RBC")
			{
				if(!props.get('ringBondCount'))
					props.set('ringBondCount', new util.Map());
				props.get('ringBondCount').update(mf.readKeyValuePairs(propertyData));
			}
			else if(type == "SUB")
			{
				if(!props.get('substitutionCount'))
					props.set('substitutionCount', new util.Map());
				props.get('substitutionCount').update(mf.readKeyValuePairs(propertyData));
			}
			else if(type == "UNS")
			{
				if(!props.get('unsaturatedAtom'))
					props.set('unsaturatedAtom', new util.Map());
				props.get('unsaturatedAtom').update(mf.readKeyValuePairs(propertyData));
				// else if (type == "LIN") // link atom
			}
			else if(type == "RGP")
			{ // rgroup atom
				if(!props.get('rglabel'))
					props.set('rglabel', new util.Map());
				var rglabels = props.get('rglabel');
				var a2rs = mf.readKeyMultiValuePairs(propertyData);
				for(var a2ri = 0; a2ri < a2rs.length; a2ri++)
				{
					var a2r = a2rs[a2ri];
					rglabels.set(a2r[0], (rglabels.get(a2r[0]) || 0) | (1 << (a2r[1] - 1)));
				}
			}
			else if(type == "LOG")
			{ // rgroup atom
				propertyData = propertyData.slice(4);
				var rgid = mf.parseDecimalInt(propertyData.slice(0, 3).trim());
				var iii = mf.parseDecimalInt(propertyData.slice(4, 7).trim());
				var hhh = mf.parseDecimalInt(propertyData.slice(8, 11).trim());
				var ooo = propertyData.slice(12).trim();
				var logic = {};
				if(iii > 0)
					logic.ifthen = iii;
				logic.resth = hhh == 1;
				logic.range = ooo;
				rLogic[rgid] = logic;
			}
			else if(type == "APO")
			{
				if(!props.get('attpnt'))
					props.set('attpnt', new util.Map());
				props.get('attpnt').update(mf.readKeyValuePairs(propertyData));
			}
			else if(type == "ALS")
			{ // atom list
				if(!props.get('atomList'))
					props.set('atomList', new util.Map());
				var list = mf.parsePropertyLineAtomList(
					mf.partitionLine(propertyData, [1, 3, 3, 1, 1, 1]),
					mf.partitionLineFixed(propertyData.slice(10), 4, false));
				props.get('atomList').update(
					list);
				if(!props.get('label'))
					props.set('label', new util.Map());
				for(var aid in list) props.get('label').set(aid, 'L#');
			}
			else if(type == "STY")
			{ // introduce s-group
				mf.initSGroup(sGroups, propertyData);
			}
			else if(type == "SST")
			{
				mf.applySGroupProp(sGroups, 'subtype', propertyData);
			}
			else if(type == "SLB")
			{
				mf.applySGroupProp(sGroups, 'label', propertyData, true);
			}
			else if(type == "SPL")
			{
				mf.applySGroupProp(sGroups, 'parent', propertyData, true, true);
			}
			else if(type == "SCN")
			{
				mf.applySGroupProp(sGroups, 'connectivity', propertyData);
			}
			else if(type == "SAL")
			{
				mf.applySGroupArrayProp(sGroups, 'atoms', propertyData, -1);
			}
			else if(type == "SBL")
			{
				mf.applySGroupArrayProp(sGroups, 'bonds', propertyData, -1);
			}
			else if(type == "SPA")
			{
				mf.applySGroupArrayProp(sGroups, 'patoms', propertyData, -1);
			}
			else if(type == "SMT")
			{
				var sid = mf.parseDecimalInt(propertyData.slice(0, 4)) - 1;
				sGroups[sid].data.subscript = propertyData.slice(4).trim();
			}
			else if(type == "SDT")
			{
				mf.applyDataSGroupDesc(sGroups, propertyData);
			}
			else if(type == "SDD")
			{
				mf.applyDataSGroupInfoLine(sGroups, propertyData);
			}
			else if(type == "SCD")
			{
				mf.applyDataSGroupDataLine(sGroups, propertyData, false);
			}
			else if(type == "SED")
			{
				mf.applyDataSGroupDataLine(sGroups, propertyData, true);
			}
		}
		++shift;
	}
	return props;
};