Beispiel #1
0
		// compare to another molecule instance; null is equivalent to empty; return values:
		//     -1 if Mol < Other
		//	    0 if Mol == Other
		//	    1 if Mol > Other 
		//  can be used to sort molecules, albeit crudely; does not do any kind of canonical preprocessing
		public virtual int CompareTo(Molecule Other)
		{
			if (Other == null)
				return NumAtoms() == 0?0:1; // null is equivalent to empty
			if (NumAtoms() < Other.NumAtoms())
				return - 1;
			if (NumAtoms() > Other.NumAtoms())
				return 1;
			if (NumBonds() < Other.NumBonds())
				return - 1;
			if (NumBonds() > Other.NumBonds())
				return 1;
			
			for (int n = 1; n <= NumAtoms(); n++)
			{
				int c = String.CompareOrdinal(AtomElement(n), Other.AtomElement(n));
				if (c != 0)
					return c;
				if (AtomX(n) < Other.AtomX(n))
					return - 1;
				if (AtomX(n) > Other.AtomX(n))
					return 1;
				if (AtomY(n) < Other.AtomY(n))
					return - 1;
				if (AtomY(n) > Other.AtomY(n))
					return 1;
				if (AtomCharge(n) < Other.AtomCharge(n))
					return - 1;
				if (AtomCharge(n) > Other.AtomCharge(n))
					return 1;
				if (AtomUnpaired(n) < Other.AtomUnpaired(n))
					return - 1;
				if (AtomUnpaired(n) > Other.AtomUnpaired(n))
					return 1;
				if (AtomHExplicit(n) < Other.AtomHExplicit(n))
					return - 1;
				if (AtomHExplicit(n) > Other.AtomHExplicit(n))
					return 1;
			}
			for (int n = 1; n <= NumBonds(); n++)
			{
				if (BondFrom(n) < Other.BondFrom(n))
					return - 1;
				if (BondFrom(n) > Other.BondFrom(n))
					return 1;
				if (BondTo(n) < Other.BondTo(n))
					return - 1;
				if (BondTo(n) > Other.BondTo(n))
					return 1;
				if (BondOrder(n) < Other.BondOrder(n))
					return - 1;
				if (BondOrder(n) > Other.BondOrder(n))
					return 1;
				if (BondType(n) < Other.BondType(n))
					return - 1;
				if (BondType(n) > Other.BondType(n))
					return 1;
			}
			
			return 0;
		}
		public static void  WriteNative(System.IO.StreamWriter output, Molecule mol)
		{
			//UPGRADE_ISSUE: Class 'java.text.DecimalFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextDecimalFormat'"
			//UPGRADE_ISSUE: Constructor 'java.text.DecimalFormat.DecimalFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextDecimalFormat'"
			// DecimalFormat fmt = new DecimalFormat("0.0000");
            string fmtStr = "N4";
			
			output.Write("SketchEl!(" + mol.NumAtoms() + "," + mol.NumBonds() + ")\n");
			for (int n = 1; n <= mol.NumAtoms(); n++)
			{
				System.String hy = mol.AtomHExplicit(n) != Molecule.HEXPLICIT_UNKNOWN?("e" + mol.AtomHExplicit(n)):("i" + mol.AtomHydrogens(n));
                output.Write(mol.AtomElement(n) + "=" + mol.AtomX(n).ToString(fmtStr) + "," + mol.AtomY(n).ToString(fmtStr) + ";" + mol.AtomCharge(n) + "," + mol.AtomUnpaired(n) + "," + hy + "\n");
			}
			for (int n = 1; n <= mol.NumBonds(); n++)
			{
				output.Write(mol.BondFrom(n) + "-" + mol.BondTo(n) + "=" + mol.BondOrder(n) + "," + mol.BondType(n) + "\n");
			}
			output.Write("!End\n");
			
			output.Flush();
		}