diff --git a/mordred/mopac/calculate.py b/mordred/mopac/calculate.py index 025b4796..13b5367a 100644 --- a/mordred/mopac/calculate.py +++ b/mordred/mopac/calculate.py @@ -9,7 +9,7 @@ from rdkit.Chem import rdForceFieldHelpers -from .parser import parse_output, get_dipole_from_arc +from .parser import parse_output from .generate import generate_mopac_internal_input try: @@ -69,7 +69,6 @@ def calculate(mol, condition="PM3 XYZ MMOK", confId=-1, timeout=None, executable stdout = run_process([executable], cwd=d, timeout=timeout, env={ "FOR005": "mol.dat", "FOR006": "mol.out", - "FOR012": "mol.arc", }) result = parse_output( open(os.path.join(d, "mol.out"), "r") @@ -77,8 +76,6 @@ def calculate(mol, condition="PM3 XYZ MMOK", confId=-1, timeout=None, executable else StringIO(stdout.decode("UTF-8")), ) - result.dipole = get_dipole_from_arc(open(os.path.join(d, "mol.arc"), "r")) - conf = mol.GetConformer(confId) for i, xyz in enumerate(result.coordinates): conf.SetAtomPosition(i, xyz) diff --git a/mordred/mopac/parser.py b/mordred/mopac/parser.py index 678cd6f9..78517cae 100644 --- a/mordred/mopac/parser.py +++ b/mordred/mopac/parser.py @@ -8,6 +8,7 @@ ("ionization_potential", float, re.compile(r"\s*IONIZATION POTENTIAL\s*=\s*(-?[0-9.]+)")), ("num_of_filled_levels", int, re.compile(r"\s*NO. OF FILLED LEVELS\s*=\s*(-?[0-9.]+)")), ] +dipole_re = re.compile(r"^ SUM +(?:-?[0-9.]+) +(?:-?[0-9.]+) +(?:-?[0-9.]+) +(-?[0-9.]+)") class Result(object): @@ -57,7 +58,7 @@ def skip(n, it): next(it) -def parse_output(fp, eigenvalues=True, coordinates=True): +def parse_output(fp): i = 0 result = Result() @@ -72,47 +73,40 @@ def parse_output(fp, eigenvalues=True, coordinates=True): if i >= len(regexes): break - if eigenvalues: - skip_to("EIGENVALUES", it) - skip(1, it) + skip_to("EIGENVALUES", it) + skip(1, it) - evs = [] - for line in it: - line = line.rstrip() - if not line: - break - - for i in range(int(len(line) // 10)): - evs.append(float(line[10 * i:10 * (i + 1)])) - - result.eigenvalues = evs - - if coordinates: - skip_to("CARTESIAN COORDINATES", it) - skip(3, it) + evs = [] + for line in it: + line = line.rstrip() + if not line: + break - crd = [] - for line in it: - line = line.rstrip() - if not line: - break + for i in range(int(len(line) // 10)): + evs.append(float(line[10 * i:10 * (i + 1)])) - crd.append([float(line[30:40]), float(line[40:50]), float(line[50:60])]) + result.eigenvalues = evs - result.coordinates = crd + skip_to("DIPOLE X Y Z TOTAL", it) + skip(2, it) + matched = dipole_re.match(next(it)) + if matched is not None: + result.dipole = float(matched.group(1)) - return result + skip_to("CARTESIAN COORDINATES", it) + skip(3, it) + crd = [] + for line in it: + line = line.rstrip() + if not line: + break -re_dipole = re.compile(r"\s*DIPOLE\s*=\s*(-?[0-9.]+)") + crd.append([float(line[30:40]), float(line[40:50]), float(line[50:60])]) + result.coordinates = crd -def get_dipole_from_arc(fp): - with fp: - for line in fp: - matched = re_dipole.match(line) - if matched: - return float(matched.group(1)) + return result def main(): diff --git a/mordred/tests/references/QM.yaml b/mordred/tests/references/QM.yaml index e1ac1c37..9b0531d6 100644 --- a/mordred/tests/references/QM.yaml +++ b/mordred/tests/references/QM.yaml @@ -1,98 +1,98 @@ # Mopac - names: ['AM1_dipole', 'AM1_E', 'AM1_Eele', 'AM1_HF', 'AM1_IP', 'AM1_LUMO', 'AM1_HOMO'] - digit: 5 + digit: 3 results: - Hexane: [0.00625, -962.21925, -4456.97693, -38.78988, 11.15696, 3.85906, -11.15696] + Hexane: [0.006, -962.21925, -4456.97693, -38.78988, 11.15696, 3.85906, -11.15696] Benzene: [0.0, -850.31811, -3257.98562, 22.44232, 9.6691, 0.53931, -9.6691] - Caffeine: [3.64982, -2627.83146, -14490.08293, 26.07287, 9.11038, -0.18906, -9.11038] - Cyanidin: [4.59005, -3985.57374, -23893.95614, 2.87455, 12.2398, -6.06003, -12.2398] - Lycopene: [0.51317, -5888.87381, -52757.31325, 112.84233, 8.08331, -0.45078, -8.08331] - Epicatechin: [1.60446, -4035.45562, -25329.90962, -202.70645, 8.97955, -0.0452, -8.97955] - Limonene: [0.35559, -1500.67154, -8397.02036, 1.88402, 9.28934, 1.21221, -9.28934] - Allicin: [2.3365, -1613.30263, -7198.57743, 11.91846, 9.18669, -1.54097, -9.18669] - Glutathione: [2.4923, -4253.81825, -25978.34563, -247.91703, 9.23846, 0.39092, -9.23846] - Digoxin: [10.43907, -10619.59174, -119713.02556, -618.08041, 10.28823, -0.22483, -10.28823] - Capsaicin: [3.27242, -3844.92235, -26066.35975, -110.43516, 9.03938, 0.02417, -9.03938] - EllagicAcid: [2.26746, -4436.78882, -26733.93689, -235.93439, 9.28736, -1.56898, -9.28736] - Astaxanthin: [2.32726, -7115.74156, -65423.45136, -43.09483, 8.6865, -0.36725, -8.6865] - DMSO: [3.83746, -853.23669, -2565.04208, -35.88916, 9.62597, 0.58229, -9.62597] - DiethylThioketone: [3.52237, -971.77192, -4045.00393, 12.16894, 8.57107, -1.05092, -8.57107] - VinylsulfonicAcid: [3.11885, -1465.8629, -4716.24079, -95.23211, 11.99915, -0.93524, -11.99915] - Thiophene: [0.13013, -760.89477, -2539.13976, 28.6939, 9.27526, 0.15925, -9.27526] - Triethoxyphosphine: [3.09539, -2066.28866, -10055.73374, -192.2216, 9.19429, 1.26865, -9.19429] - MethylphosphonicAcid: [2.27409, -1289.66441, -3881.76118, -216.75491, 11.35945, 0.58765, -11.35945] - MethylCyclopropane: [0.08446, -621.60369, -2245.9639, 12.60945, 10.85938, 2.99573, -10.85938] - Acetonitrile: [2.89495, -503.83911, -1204.94467, 20.4822, 12.57791, 1.7033, -12.57791] - Histidine: [3.45245, -2153.32036, -9998.85032, -40.9128, 9.12414, 0.48558, -9.12414] - Ammonia: [1.94583, -248.55727, -432.33114, -6.50923, 10.67571, 4.1519, -10.67571] - PentachloroLambda5Phosphane: [1.08631, -1997.23072, -5366.09107, -51.63969, 12.45208, -4.44492, -12.45208] - Acetylene: [0.00017, -281.38483, -561.79964, 54.86042, 11.4532, 2.04087, -11.4532] - Carbonate: [1.32617, -1085.28503, -2345.37562, -23.34494, -2.47545, 14.58215, 2.47545] + Caffeine: [3.65, -2627.83146, -14490.08293, 26.07287, 9.11038, -0.18906, -9.11038] + Cyanidin: [4.59, -3985.57374, -23893.95614, 2.87455, 12.2398, -6.06003, -12.2398] + Lycopene: [0.513, -5888.87381, -52757.31325, 112.84233, 8.08331, -0.45078, -8.08331] + Epicatechin: [1.604, -4035.45562, -25329.90962, -202.70645, 8.97955, -0.0452, -8.97955] + Limonene: [0.356, -1500.67154, -8397.02036, 1.88402, 9.28934, 1.21221, -9.28934] + Allicin: [2.337, -1613.30263, -7198.57743, 11.91846, 9.18669, -1.54097, -9.18669] + Glutathione: [2.492, -4253.81825, -25978.34563, -247.91703, 9.23846, 0.39092, -9.23846] + Digoxin: [10.439, -10619.59174, -119713.02556, -618.08041, 10.28823, -0.22483, -10.28823] + Capsaicin: [3.272, -3844.92235, -26066.35975, -110.43516, 9.03938, 0.02417, -9.03938] + EllagicAcid: [2.267, -4436.78882, -26733.93689, -235.93439, 9.28736, -1.56898, -9.28736] + Astaxanthin: [2.327, -7115.74156, -65423.45136, -43.09483, 8.6865, -0.36725, -8.6865] + DMSO: [3.837, -853.23669, -2565.04208, -35.88916, 9.62597, 0.58229, -9.62597] + DiethylThioketone: [3.522, -971.77192, -4045.00393, 12.16894, 8.57107, -1.05092, -8.57107] + VinylsulfonicAcid: [3.119, -1465.8629, -4716.24079, -95.23211, 11.99915, -0.93524, -11.99915] + Thiophene: [0.13, -760.89477, -2539.13976, 28.6939, 9.27526, 0.15925, -9.27526] + Triethoxyphosphine: [3.095, -2066.28866, -10055.73374, -192.2216, 9.19429, 1.26865, -9.19429] + MethylphosphonicAcid: [2.274, -1289.66441, -3881.76118, -216.75491, 11.35945, 0.58765, -11.35945] + MethylCyclopropane: [0.084, -621.60369, -2245.9639, 12.60945, 10.85938, 2.99573, -10.85938] + Acetonitrile: [2.895, -503.83911, -1204.94467, 20.4822, 12.57791, 1.7033, -12.57791] + Histidine: [3.452, -2153.32036, -9998.85032, -40.9128, 9.12414, 0.48558, -9.12414] + Ammonia: [1.946, -248.55727, -432.33114, -6.50923, 10.67571, 4.1519, -10.67571] + PentachloroLambda5Phosphane: [1.086, -1997.23072, -5366.09107, -51.63969, 12.45208, -4.44492, -12.45208] + Acetylene: [0.0, -281.38483, -561.79964, 54.86042, 11.4532, 2.04087, -11.4532] + Carbonate: [1.326, -1085.28503, -2345.37562, -23.34494, -2.47545, 14.58215, 2.47545] Oxygen: [0.0, -637.08422, -1004.75191, 6.46083, 11.05542, -1.21518, -11.05542] Iodine: [0.0, -694.97972, -946.01835, 22.18121, 10.73637, -2.35287, -10.73637] - names: ['MNDO_dipole', 'MNDO_E', 'MNDO_Eele', 'MNDO_HF', 'MNDO_IP', 'MNDO_LUMO', 'MNDO_HOMO'] - digit: 5 + digit: 3 results: - Hexane: [0.01396, -967.22171, -4472.41937, -33.15622, 12.00268, 3.4721, -12.00268] + Hexane: [0.014, -967.22171, -4472.41937, -33.15622, 12.00268, 3.4721, -12.00268] Benzene: [0.0, -851.50289, -3266.61925, 22.05447, 9.46838, 0.39375, -9.46838] - Caffeine: [3.76892, -2636.38891, -14510.61739, -15.63677, 9.2797, -0.32869, -9.2797] - Cyanidin: [4.74528, -3997.76071, -23928.33064, -13.09598, 12.23767, -6.11645, -12.23767] - Lycopene: [0.16342, -5904.19082, -52828.73069, 127.30182, 8.31361, -0.63384, -8.31361] - Epicatechin: [1.33562, -4048.45795, -25366.55443, -202.20724, 8.97106, -0.1869, -8.97106] - Limonene: [0.11543, -1505.50134, -8416.18936, 5.94046, 9.65189, 0.841, -9.65189] + Caffeine: [3.769, -2636.38891, -14510.61739, -15.63677, 9.2797, -0.32869, -9.2797] + Cyanidin: [4.745, -3997.76071, -23928.33064, -13.09598, 12.23767, -6.11645, -12.23767] + Lycopene: [0.163, -5904.19082, -52828.73069, 127.30182, 8.31361, -0.63384, -8.31361] + Epicatechin: [1.336, -4048.45795, -25366.55443, -202.20724, 8.97106, -0.1869, -8.97106] + Limonene: [0.115, -1505.50134, -8416.18936, 5.94046, 9.65189, 0.841, -9.65189] Allicin: [2.214, -1685.19824, -7300.5843, 49.76466, 9.74452, -0.94139, -9.74452] - Glutathione: [1.86673, -4303.1516, -26057.29463, -211.52384, 9.98059, 0.3729, -9.98059] - Digoxin: [9.88418, -10656.50888, -119819.86003, -443.82486, 10.70398, -0.51498, -10.70398] - Capsaicin: [3.0322, -3857.76634, -26107.69358, -93.89775, 9.10792, -0.20621, -9.10792] - EllagicAcid: [2.19274, -4450.72346, -26767.43364, -262.13839, 9.27998, -1.67648, -9.27998] - Astaxanthin: [2.45644, -7135.11079, -65500.15185, -5.93564, 8.88548, -0.56311, -8.88548] - DMSO: [4.46013, -889.87617, -2616.5566, 6.50667, 9.90035, 0.53867, -9.90035] - DiethylThioketone: [2.57267, -1009.62837, -4096.0247, 10.93046, 9.18284, -0.98639, -9.18284] - VinylsulfonicAcid: [4.06648, -1500.13399, -4775.76911, 59.85507, 11.87787, -1.33569, -11.87787] - Thiophene: [0.59644, -795.98743, -2585.84484, 27.91413, 9.4173, -0.04027, -9.4173] - Triethoxyphosphine: [3.40033, -2106.68969, -10108.36226, -211.00107, 10.41753, 1.75703, -10.41753] - MethylphosphonicAcid: [2.23723, -1322.78912, -3920.64944, -148.9688, 10.86803, -0.59154, -10.86803] - MethylCyclopropane: [0.08207, -624.64914, -2255.16536, 7.36523, 11.19134, 2.68387, -11.19134] - Acetonitrile: [2.64717, -504.93217, -1209.43765, 19.66515, 12.83471, 1.62596, -12.83471] - Histidine: [3.08779, -2160.28738, -10016.97018, -46.82006, 9.12163, 0.35688, -9.12163] - Ammonia: [1.74736, -250.22652, -436.33956, -6.07674, 11.10979, 4.18895, -11.10979] - PentachloroLambda5Phosphane: [0.88929, -1928.42352, -5298.57058, -7.21258, 12.44514, -5.52111, -12.44514] - Acetylene: [0.00013, -281.6307, -564.52122, 58.16858, 10.94934, 2.12526, -10.94934] - Carbonate: [1.41521, -1089.53865, -2350.62746, -6.32239, -2.83911, 14.58199, 2.83911] + Glutathione: [1.867, -4303.1516, -26057.29463, -211.52384, 9.98059, 0.3729, -9.98059] + Digoxin: [9.884, -10656.50888, -119819.86003, -443.82486, 10.70398, -0.51498, -10.70398] + Capsaicin: [3.032, -3857.76634, -26107.69358, -93.89775, 9.10792, -0.20621, -9.10792] + EllagicAcid: [2.193, -4450.72346, -26767.43364, -262.13839, 9.27998, -1.67648, -9.27998] + Astaxanthin: [2.456, -7135.11079, -65500.15185, -5.93564, 8.88548, -0.56311, -8.88548] + DMSO: [4.460, -889.87617, -2616.5566, 6.50667, 9.90035, 0.53867, -9.90035] + DiethylThioketone: [2.573, -1009.62837, -4096.0247, 10.93046, 9.18284, -0.98639, -9.18284] + VinylsulfonicAcid: [4.066, -1500.13399, -4775.76911, 59.85507, 11.87787, -1.33569, -11.87787] + Thiophene: [0.596, -795.98743, -2585.84484, 27.91413, 9.4173, -0.04027, -9.4173] + Triethoxyphosphine: [3.400, -2106.68969, -10108.36226, -211.00107, 10.41753, 1.75703, -10.41753] + MethylphosphonicAcid: [2.237, -1322.78912, -3920.64944, -148.9688, 10.86803, -0.59154, -10.86803] + MethylCyclopropane: [0.082, -624.64914, -2255.16536, 7.36523, 11.19134, 2.68387, -11.19134] + Acetonitrile: [2.647, -504.93217, -1209.43765, 19.66515, 12.83471, 1.62596, -12.83471] + Histidine: [3.088, -2160.28738, -10016.97018, -46.82006, 9.12163, 0.35688, -9.12163] + Ammonia: [1.747, -250.22652, -436.33956, -6.07674, 11.10979, 4.18895, -11.10979] + PentachloroLambda5Phosphane: [0.889, -1928.42352, -5298.57058, -7.21258, 12.44514, -5.52111, -12.44514] + Acetylene: [0.000, -281.6307, -564.52122, 58.16858, 10.94934, 2.12526, -10.94934] + Carbonate: [1.415, -1089.53865, -2350.62746, -6.32239, -2.83911, 14.58199, 2.83911] Oxygen: [0.0, -640.35139, -1008.38629, 12.70573, 11.09888, -1.22193, -11.09888] Iodine: [0.0, -682.31766, -933.2918, 25.18404, 10.94381, -2.61982, -10.94381] - names: ['PM3_dipole', 'PM3_E', 'PM3_Eele', 'PM3_HF', 'PM3_IP', 'PM3_LUMO', 'PM3_HOMO'] - digit: 5 + digit: 3 results: - Hexane: [0.01049, -928.12877, -4402.50151, -37.5969, 11.34118, 3.51092, -11.34118] + Hexane: [0.010, -928.12877, -4402.50151, -37.5969, 11.34118, 3.51092, -11.34118] Benzene: [0.0, -802.81131, -3170.13783, 23.66224, 9.73293, 0.37688, -9.73293] - Caffeine: [3.84388, -2337.82811, -14034.10131, -34.00631, 8.91201, -0.42801, -8.91201] - Cyanidin: [4.32192, -3699.88221, -23451.96384, -1.61478, 12.23266, -6.16267, -12.23266] - Lycopene: [0.46279, -5599.95929, -52194.05245, 98.67131, 8.19607, -0.61153, -8.19607] - Epicatechin: [1.32575, -3754.53303, -24901.06305, -201.15967, 8.98257, -0.05149, -8.98257] - Limonene: [0.33918, -1431.76254, -8266.17417, -0.87119, 9.37345, 1.02591, -9.37345] - Allicin: [1.98983, -1528.70302, -7006.1083, 24.34982, 9.02828, -1.82557, -9.02828] - Glutathione: [2.22969, -3883.16472, -25446.10333, -244.83757, 9.48277, 0.03344, -9.48277] - Digoxin: [10.2155, -9957.04916, -118696.00447, -566.41335, 10.46189, -0.35357, -10.46189] - Capsaicin: [3.40494, -3592.57979, -25668.83775, -110.17512, 9.14125, -0.10103, -9.14125] - EllagicAcid: [2.21429, -4099.2631, -26220.99886, -251.47056, 9.2095, -1.51352, -9.2095] - Astaxanthin: [2.21505, -6713.11135, -64695.7037, -57.75325, 8.78334, -0.5358, -8.78334] - DMSO: [4.22076, -809.10825, -2480.96266, -36.29762, 9.19937, 0.38571, -9.19937] - DiethylThioketone: [3.47505, -932.15036, -3962.30217, 16.38141, 9.00525, -1.60381, -9.00525] - VinylsulfonicAcid: [3.5409, -1365.05252, -4546.76653, -99.94094, 11.45353, -0.36587, -11.45353] - Thiophene: [0.53316, -720.86548, -2446.82575, 31.34366, 9.57478, -0.24374, -9.57478] - Triethoxyphosphine: [3.75112, -1946.70598, -9838.68266, -181.35475, 8.49828, 1.18519, -8.49828] - MethylphosphonicAcid: [2.03503, -1201.04921, -3723.29562, -201.43805, 10.3721, 0.94633, -10.3721] - MethylCyclopropane: [0.07733, -596.80948, -2204.83408, 9.516, 11.09962, 2.94163, -11.09962] - Acetonitrile: [3.22435, -444.77038, -1130.61318, 23.56531, 12.36908, 1.41699, -12.36908] - Histidine: [3.69015, -1923.65324, -9675.54602, -55.96295, 9.30922, 0.27449, -9.30922] - Ammonia: [1.59669, -208.61509, -391.18246, -2.38374, 9.86072, 3.30044, -9.86072] - PentachloroLambda5Phosphane: [1.1703, -1707.10776, -5020.34641, -83.28199, 12.05747, -3.5941, -12.05747] - Acetylene: [0.00017, -265.74058, -539.66598, 50.85433, 11.52119, 1.9548, -11.52119] - Carbonate: [1.44854, -995.71136, -2247.65568, -29.89778, -2.54552, 14.3055, 2.54552] + Caffeine: [3.844, -2337.82811, -14034.10131, -34.00631, 8.91201, -0.42801, -8.91201] + Cyanidin: [4.322, -3699.88221, -23451.96384, -1.61478, 12.23266, -6.16267, -12.23266] + Lycopene: [0.463, -5599.95929, -52194.05245, 98.67131, 8.19607, -0.61153, -8.19607] + Epicatechin: [1.326, -3754.53303, -24901.06305, -201.15967, 8.98257, -0.05149, -8.98257] + Limonene: [0.339, -1431.76254, -8266.17417, -0.87119, 9.37345, 1.02591, -9.37345] + Allicin: [1.990, -1528.70302, -7006.1083, 24.34982, 9.02828, -1.82557, -9.02828] + Glutathione: [2.230, -3883.16472, -25446.10333, -244.83757, 9.48277, 0.03344, -9.48277] + Digoxin: [10.215, -9957.04916, -118696.00447, -566.41335, 10.46189, -0.35357, -10.46189] + Capsaicin: [3.405, -3592.57979, -25668.83775, -110.17512, 9.14125, -0.10103, -9.14125] + EllagicAcid: [2.214, -4099.2631, -26220.99886, -251.47056, 9.2095, -1.51352, -9.2095] + Astaxanthin: [2.215, -6713.11135, -64695.7037, -57.75325, 8.78334, -0.5358, -8.78334] + DMSO: [4.221, -809.10825, -2480.96266, -36.29762, 9.19937, 0.38571, -9.19937] + DiethylThioketone: [3.475, -932.15036, -3962.30217, 16.38141, 9.00525, -1.60381, -9.00525] + VinylsulfonicAcid: [3.541, -1365.05252, -4546.76653, -99.94094, 11.45353, -0.36587, -11.45353] + Thiophene: [0.533, -720.86548, -2446.82575, 31.34366, 9.57478, -0.24374, -9.57478] + Triethoxyphosphine: [3.751, -1946.70598, -9838.68266, -181.35475, 8.49828, 1.18519, -8.49828] + MethylphosphonicAcid: [2.035, -1201.04921, -3723.29562, -201.43805, 10.3721, 0.94633, -10.3721] + MethylCyclopropane: [0.077, -596.80948, -2204.83408, 9.516, 11.09962, 2.94163, -11.09962] + Acetonitrile: [3.224, -444.77038, -1130.61318, 23.56531, 12.36908, 1.41699, -12.36908] + Histidine: [3.690, -1923.65324, -9675.54602, -55.96295, 9.30922, 0.27449, -9.30922] + Ammonia: [1.597, -208.61509, -391.18246, -2.38374, 9.86072, 3.30044, -9.86072] + PentachloroLambda5Phosphane: [1.170, -1707.10776, -5020.34641, -83.28199, 12.05747, -3.5941, -12.05747] + Acetylene: [0.000, -265.74058, -539.66598, 50.85433, 11.52119, 1.9548, -11.52119] + Carbonate: [1.449, -995.71136, -2247.65568, -29.89778, -2.54552, 14.3055, 2.54552] Oxygen: [0.0, -583.03039, -954.37288, 18.89536, 10.58743, -0.8008, -10.58743] Iodine: [0.0, -577.94491, -825.53237, 20.76085, 9.52824, -3.79287, -9.52824]