예제 #1
0
		public static Molecule ReadMDLMOL(StreamReader in_Renamed)
		{
			Molecule mol = new Molecule();
			//UPGRADE_NOTE: Final was removed from the declaration of 'GENERIC_ERROR '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
			System.String GENERIC_ERROR = "Invalid MDL MOL file.";
			
			try
			{
				System.String line = null;
				for (int n = 0; n < 4; n++)
					line = in_Renamed.ReadLine();
				if (line == null || !line.Substring(34, (39) - (34)).Equals("V2000"))
					throw new System.IO.IOException(GENERIC_ERROR);
				int numAtoms = System.Int32.Parse(line.Substring(0, (3) - (0)).Trim());
				int numBonds = System.Int32.Parse(line.Substring(3, (6) - (3)).Trim());
				
				for (int n = 0; n < numAtoms; n++)
				{
					line = in_Renamed.ReadLine();
					
					double x = System.Double.Parse(line.Substring(0, (10) - (0)).Trim());
					double y = System.Double.Parse(line.Substring(10, (20) - (10)).Trim());
					System.String el = line.Substring(31, (33) - (31)).Trim();
					int chg = System.Int32.Parse(line.Substring(36, (39) - (36)).Trim()), rad = 0;
					
					if (chg <= 3)
					{
					}
					else if (chg == 4)
					{
						chg = 0; rad = 2;
					}
					else
						chg = 4 - chg;
					
					mol.AddAtom(el, x, y, chg, rad);
				}
				for (int n = 0; n < numBonds; n++)
				{
					line = in_Renamed.ReadLine();
					
					int from = System.Int32.Parse(line.Substring(0, (3) - (0)).Trim()), to = System.Int32.Parse(line.Substring(3, (6) - (3)).Trim());
					int type = System.Int32.Parse(line.Substring(6, (9) - (6)).Trim()), stereo = System.Int32.Parse(line.Substring(9, (12) - (9)).Trim());
					
					if (from == to || from < 1 || from > numAtoms || to < 1 || to > numAtoms)
						throw new System.IO.IOException(GENERIC_ERROR);
					
					int order = type >= 1 && type <= 3?type:1;
					int style = Molecule.BONDTYPE_NORMAL;
					if (stereo == 1)
						style = Molecule.BONDTYPE_INCLINED;
					else if (stereo == 6)
						style = Molecule.BONDTYPE_DECLINED;
					else if (stereo == 3 || stereo == 4)
						style = Molecule.BONDTYPE_UNKNOWN;
					
					mol.AddBond(from, to, order, style);
				}
				while (true)
				{
					line = in_Renamed.ReadLine();
					if (line.StartsWith("M  END"))
						break;
					
					int type = 0;
					if (line.StartsWith("M  CHG"))
						type = 1;
					else if (line.StartsWith("M  RAD"))
						type = 2;
					if (type > 0)
					{
						int len = System.Int32.Parse(line.Substring(6, (9) - (6)).Trim());
						for (int n = 0; n < len; n++)
						{
							int apos = System.Int32.Parse(line.Substring(9 + 8 * n, (13 + 8 * n) - (9 + 8 * n)).Trim());
							int aval = System.Int32.Parse(line.Substring(13 + 8 * n, (17 + 8 * n) - (13 + 8 * n)).Trim());
							if (type == 1)
								mol.SetAtomCharge(apos, aval);
							else
								mol.SetAtomUnpaired(apos, aval);
						}
					}
				}
			}
			catch (System.Exception)
			{
				throw new System.IO.IOException(GENERIC_ERROR);
			}
			
			
			return mol;
		}