本文整理匯總了Python中pymatgen.io.qchem.inputs.QCInput.write_file方法的典型用法代碼示例。如果您正苦於以下問題:Python QCInput.write_file方法的具體用法?Python QCInput.write_file怎麽用?Python QCInput.write_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymatgen.io.qchem.inputs.QCInput
的用法示例。
在下文中一共展示了QCInput.write_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: opt_with_frequency_flattener
# 需要導入模塊: from pymatgen.io.qchem.inputs import QCInput [as 別名]
# 或者: from pymatgen.io.qchem.inputs.QCInput import write_file [as 別名]
def opt_with_frequency_flattener(cls,
qchem_command,
multimode="openmp",
input_file="mol.qin",
output_file="mol.qout",
qclog_file="mol.qclog",
max_iterations=10,
max_molecule_perturb_scale=0.3,
check_connectivity=True,
**QCJob_kwargs):
"""
Optimize a structure and calculate vibrational frequencies to check if the
structure is in a true minima. If a frequency is negative, iteratively
perturbe the geometry, optimize, and recalculate frequencies until all are
positive, aka a true minima has been found.
Args:
qchem_command (str): Command to run QChem.
multimode (str): Parallelization scheme, either openmp or mpi.
input_file (str): Name of the QChem input file.
output_file (str): Name of the QChem output file.
max_iterations (int): Number of perturbation -> optimization -> frequency
iterations to perform. Defaults to 10.
max_molecule_perturb_scale (float): The maximum scaled perturbation that
can be applied to the molecule. Defaults to 0.3.
check_connectivity (bool): Whether to check differences in connectivity
introduced by structural perturbation. Defaults to True.
**QCJob_kwargs: Passthrough kwargs to QCJob. See
:class:`custodian.qchem.jobs.QCJob`.
"""
min_molecule_perturb_scale = 0.1
scale_grid = 10
perturb_scale_grid = (
max_molecule_perturb_scale - min_molecule_perturb_scale
) / scale_grid
if not os.path.exists(input_file):
raise AssertionError('Input file must be present!')
orig_opt_input = QCInput.from_file(input_file)
orig_opt_rem = copy.deepcopy(orig_opt_input.rem)
orig_freq_rem = copy.deepcopy(orig_opt_input.rem)
orig_freq_rem["job_type"] = "freq"
first = True
reversed_direction = False
num_neg_freqs = []
for ii in range(max_iterations):
yield (QCJob(
qchem_command=qchem_command,
multimode=multimode,
input_file=input_file,
output_file=output_file,
qclog_file=qclog_file,
suffix=".opt_" + str(ii),
backup=first,
**QCJob_kwargs))
first = False
opt_outdata = QCOutput(output_file + ".opt_" + str(ii)).data
if opt_outdata["structure_change"] == "unconnected_fragments" and not opt_outdata["completion"]:
print("Unstable molecule broke into unconnected fragments which failed to optimize! Exiting...")
break
else:
freq_QCInput = QCInput(
molecule=opt_outdata.get("molecule_from_optimized_geometry"),
rem=orig_freq_rem,
opt=orig_opt_input.opt,
pcm=orig_opt_input.pcm,
solvent=orig_opt_input.solvent)
freq_QCInput.write_file(input_file)
yield (QCJob(
qchem_command=qchem_command,
multimode=multimode,
input_file=input_file,
output_file=output_file,
qclog_file=qclog_file,
suffix=".freq_" + str(ii),
backup=first,
**QCJob_kwargs))
outdata = QCOutput(output_file + ".freq_" + str(ii)).data
errors = outdata.get("errors")
if len(errors) != 0:
raise AssertionError('No errors should be encountered while flattening frequencies!')
if outdata.get('frequencies')[0] > 0.0:
print("All frequencies positive!")
break
else:
num_neg_freqs += [sum(1 for freq in outdata.get('frequencies') if freq < 0)]
if len(num_neg_freqs) > 1:
if num_neg_freqs[-1] == num_neg_freqs[-2] and not reversed_direction:
reversed_direction = True
elif num_neg_freqs[-1] == num_neg_freqs[-2] and reversed_direction:
if len(num_neg_freqs) < 3:
raise AssertionError("ERROR: This should only be possible after at least three frequency flattening iterations! Exiting...")
else:
raise Exception("ERROR: Reversing the perturbation direction still could not flatten any frequencies. Exiting...")
elif num_neg_freqs[-1] != num_neg_freqs[-2] and reversed_direction:
reversed_direction = False
negative_freq_vecs = outdata.get("frequency_mode_vectors")[0]
#.........這裏部分代碼省略.........