Skip to content

Commit

Permalink
Merge pull request #28 from carlosbornes/master
Browse files Browse the repository at this point in the history
Re-order channels in write_spinsys for simpson.py
  • Loading branch information
jkshenton authored Oct 18, 2024
2 parents d260d93 + 11216f6 commit a9d67ff
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions soprano/calculate/nmr/simpson.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def write_spinsys(
path=None,
ref={},
grad=-1.0,
obs_nuc=None,
):
"""
Write a .spinsys input file for use with SIMPSON, given the details of a
Expand Down Expand Up @@ -99,7 +100,8 @@ def write_spinsys(
| list is provided, it should be have one value
| per site. Defaults to a gradient of -1.0 for
| all elements.
| obs_nuc (str) : specify the nucleus to be observed, e.g. 1H.
| Returns:
| file_contents (str): spinsys file in string format. Only returned if
| no save path is provided.
Expand All @@ -116,9 +118,21 @@ def write_spinsys(

nuclei = [str(i) + n for i, n in zip(isotope_list, nuclei)]

# Ensure obs_nuc appears first in channels
if obs_nuc is not None:
# Check if obs_nuc is in nuclei
if obs_nuc not in nuclei:
raise ValueError(
f"{obs_nuc} not found in the list of nuclei"
)
else:
channels = [obs_nuc] + [n for n in sorted(set(nuclei)) if n != obs_nuc]
else:
channels = sorted(set(nuclei))

# Build header
header = _header_template.format(
channels=" ".join(set(nuclei)), nuclei=" ".join(nuclei)
channels=" ".join(channels), nuclei=" ".join(nuclei)
)

# Build MS block
Expand Down

0 comments on commit a9d67ff

Please sign in to comment.