Skip to content

Commit

Permalink
add commit ref to MOFid and MOFkey
Browse files Browse the repository at this point in the history
  • Loading branch information
dweber2022 committed Aug 27, 2024
1 parent 6d92577 commit e45deec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Python/id_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def extract_topology(mof_path):
return 'MISMATCH'
return first_net

def assemble_mofid(fragments, topology, cat = None, mof_name='NAME_GOES_HERE'):
def assemble_mofid(fragments, topology, cat = None, mof_name='NAME_GOES_HERE', commit_ref = "NO_REF"):
# Assemble the MOFid string from its components
mofid = '.'.join(fragments) + ' '
mofid = mofid + 'MOFid-v1' + '.'
Expand All @@ -155,12 +155,13 @@ def assemble_mofid(fragments, topology, cat = None, mof_name='NAME_GOES_HERE'):
mofid = mofid + 'NA'
if mofid.startswith(' '): # Null linkers. Make .smi compatible
mofid = '*' + mofid + 'no_mof'
mofid = mofid + '.' + commit_ref
mofid = mofid + ';' + mof_name
return mofid

def assemble_mofkey(base_mofkey, base_topology):
def assemble_mofkey(base_mofkey, base_topology, commit_ref="NO_REF"):
# Add a topology to an existing MOFkey
return base_mofkey.replace('MOFkey-v1', 'MOFkey-v1.' + base_topology)
return base_mofkey.replace('MOFkey-v1', 'MOFkey-v1.' + base_topology + '.' + commit_ref)

def parse_mofid(mofid):
# Deconstruct a MOFid string into its pieces
Expand Down
8 changes: 5 additions & 3 deletions Python/run_mofid.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ def cif2mofid(cif_path,output_path=DEFAULT_OUTPUT_PATH):

mof_name = os.path.splitext(os.path.basename(cif_path))[0]
mofkey = base_mofkey
with open('.git/ORIG_HEAD', mode='r') as f:
commit_ref = f.read()[:8]

if topology != 'NA':
base_topology = topology.split(',')[0]
mofkey = assemble_mofkey(mofkey, base_topology)
mofkey = assemble_mofkey(mofkey, base_topology, commit_ref=commit_ref)

all_fragments = []
all_fragments.extend(node_fragments)
all_fragments.extend(linker_fragments)
all_fragments.sort()
mofid = assemble_mofid(all_fragments, topology, cat,
mof_name=mof_name)
mofid = assemble_mofid(all_fragments, topology, cat=cat,
mof_name=mof_name, commit_ref=commit_ref)
parsed = parse_mofid(mofid)

identifiers = {
Expand Down

0 comments on commit e45deec

Please sign in to comment.