1 | #!/bin/env python3
|
---|
2 | # vi:set expandtab shiftwidth=4:
|
---|
3 |
|
---|
4 | import gc
|
---|
5 | import os
|
---|
6 | import subprocess
|
---|
7 | import sys
|
---|
8 | from chimerax.mmcif import open_mmcif
|
---|
9 |
|
---|
10 | CIF_PARENT = "/databases/mol/mmCIF"
|
---|
11 | current_memory_usage = None
|
---|
12 |
|
---|
13 |
|
---|
14 | def get_memory_use():
|
---|
15 | gc.collect()
|
---|
16 | output = subprocess.check_output(['/usr/bin/pmap', str(os.getpid())])
|
---|
17 | usage = output.split()[-1].decode()
|
---|
18 | return usage
|
---|
19 |
|
---|
20 |
|
---|
21 | def print_delta_memory(tag, first, second):
|
---|
22 | delta = int(second[:-1]) - int(first[:-1])
|
---|
23 | print(f"{tag}: {delta}{first[-1]}")
|
---|
24 |
|
---|
25 |
|
---|
26 | def print_increased_memory():
|
---|
27 | global current_memory_usage
|
---|
28 | if current_memory_usage is None:
|
---|
29 | current_memory_usage = start_usage
|
---|
30 | usage = get_memory_use()
|
---|
31 | print_delta_memory("Increased memory use", current_memory_usage, usage)
|
---|
32 | current_memory_usage = usage
|
---|
33 |
|
---|
34 |
|
---|
35 | def read_files():
|
---|
36 | global start_usage
|
---|
37 | start_usage = get_memory_use()
|
---|
38 | print(f"Starting memory use: {start_usage}")
|
---|
39 | for dirpath, dirnames, filenames in os.walk(CIF_PARENT):
|
---|
40 | # print(dirpath, flush=True)
|
---|
41 | if not filenames:
|
---|
42 | # print('no filenames. dirname=', dirnames)
|
---|
43 | continue
|
---|
44 | for fn in filenames:
|
---|
45 | full_path = os.path.join(dirpath, fn)
|
---|
46 | print(' --', fn, flush=True)
|
---|
47 | models = open_mmcif(session, full_path, auto_style=False, log_info=False, slider=False)
|
---|
48 | del models
|
---|
49 | gc.collect()
|
---|
50 | print_increased_memory()
|
---|
51 |
|
---|
52 |
|
---|
53 | if __name__.startswith("ChimeraX_sandbox_"):
|
---|
54 | read_files()
|
---|