Skip to content

Instantly share code, notes, and snippets.

@numpde
Created March 29, 2025 07:01
Show Gist options
  • Save numpde/da6e53c97dcdf3bc9ed8fa61406106b8 to your computer and use it in GitHub Desktop.
Save numpde/da6e53c97dcdf3bc9ed8fa61406106b8 to your computer and use it in GitHub Desktop.
How to run MestReNova quietly (on Linux)
def sim_1hnmr(smiles: str):
if not smiles:
return
if not MolFromSmiles(smiles):
return
smiles = CanonSmiles(smiles)
with tempfile.NamedTemporaryFile(mode='wt', suffix=".csv") as peaks_file:
display_num = os.getpid() # Use unique display per process
# Start virtual X server for this process
xvfb_cmd = f"Xvfb :{display_num} -screen 0 1024x768x24 2> /dev/null &"
os.system(xvfb_cmd)
# Run MestReNova with isolated display
env = os.environ.copy()
env["DISPLAY"] = f":{display_num}"
subprocess.run(
args=[MRN_EXE, MRN_1H_SCRIPT, "-sf", f"predict_1H,{smiles},{peaks_file.name}"],
env=env,
stderr=subprocess.DEVNULL,
)
peaks_file.flush()
# Stop Xvfb after running MestReNova
os.system(f"pkill -f 'Xvfb :{display_num}'")
with open(peaks_file.name, mode='rt') as fd:
return fd.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment