Skip to content

Commit

Permalink
Added copy_model() to common
Browse files Browse the repository at this point in the history
  • Loading branch information
alongd committed Nov 1, 2023
1 parent 928f7b0 commit a767c67
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
t3 tests common module
"""

import os
from typing import Optional
import os
import shutil

from rmgpy.molecule import Molecule

Expand Down Expand Up @@ -80,3 +81,23 @@ def almost_equal(a: float,
if ratio is not None:
return abs(a - b) / abs(a) < ratio
return round(abs(a - b), places) == 0


def copy_model(model_path: str, name: str = '') -> str:
"""
Copy a model to a temporary location.
Args:
model_path (str): The path to the model to copy.
name (str, optional): A unique name for the copied model in addition to "temp_".
Returns:
str: The path to the copied model.
"""
model_path = os.path.abspath(model_path)
model_name = os.path.basename(model_path)
model_dir = os.path.dirname(model_path)
name = f'{name}_' if name else ''
new_model_path = os.path.join(model_dir, f'temp_{name}' + model_name)
shutil.copyfile(model_path, new_model_path)
return new_model_path

0 comments on commit a767c67

Please sign in to comment.