Open
Description
Hey:)
I am trying to use the following function for ConformerEnsemble_from_CREST:
ce.prune_rmsd(method = "obrms-batch")
It gives me the following error:
PermissionError: [Errno 13] Permission denied: '~\AppData\Local\Temp\tmpnp4iv4_n.xyz'
I modified the conformer.py write_xyz function by adding 2 lines (import os and os.unlink(file)):
`` def write_xyz(
self,
file: str | PathLike,
ids: Iterable[int] | None = None,
unit: str = "kcal/mol",
relative: bool = True,
separate: bool = False,
n_decimals: int = 3,
) -> None:
"""Write conformers to xyz file.
Args:
file: Filename or path object. Needs filename if `separate=True`
ids: Conformer indices (1-indexed)
unit: Output unit for energies in xyz comment field: 'hartree', 'kcal/mol',
'kJ/mol'
relative: Whether to give energies relative to lowest energy conformer
separate: Whether to write conformers to separate xyz files
n_decimals: Number of decimals for energies
Raises:
TypeError: When separate=True and file is not str
"""
if ids is None:
ids_ = np.arange(len(self.conformers))
else:
ids_ = np.array(ids) - 1
ids = ids_
# Retrieve symbols, coordinates and energies
symbols = convert_elements(self.elements, output="symbols")
conformer_coordinates = self.get_coordinates()[ids]
energies = self.get_relative_energies(unit=unit, relative=relative)[ids].round(
n_decimals
)
# Write conformers
if separate:
if not isinstance(file, str):
raise TypeError("file must be str when separate=True")
for i, coordinates, energy in zip(ids, conformer_coordinates, energies):
conf_filename = file.split(".")[0] + f"_{i + 1}.xyz"
write_xyz(conf_filename, symbols, coordinates, comments=[energy])
else:
import os
os.unlink(file)
write_xyz(file, symbols, conformer_coordinates, comments=energies)
Now the function runs without an error message.
Metadata
Metadata
Assignees
Labels
No labels