Skip to content

Commit

Permalink
modified the package conforming to python style. version 0.2.1 used f…
Browse files Browse the repository at this point in the history
…or the paper
  • Loading branch information
skatnagallu committed Feb 20, 2024
1 parent 27603f1 commit 9688951
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 46 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ignore compiled files
*.class
*.jar
*.pyc
*.DS_Store

# Ignore folders
logs/
correlationHistogramAnalysis.egg-info/
dist/

# Ignore IDE-specific files
.idea/
.vscode/
Shape_analysis.ipynb
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

Empty file.
10 changes: 5 additions & 5 deletions correlationHistogramAnalysis/correlation_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def read_epos(f):
~ Appendix A of 'Atom Probe tomography: A Users Guide',
notes on ePOS format."""
# read in the data
with open(f, 'rb') as file:
with open(f, "rb") as file:
n = len(file.read()) / 4
rs = n / 11
with open(f, 'rb') as file:
d = struct.unpack('>' + 'fffffffffII' * int(rs), file.read(4 * int(n)))
with open(f, "rb") as file:
d = struct.unpack(">" + "fffffffffII" * int(rs), file.read(4 * int(n)))
epos = np.array(d)
epos = epos.reshape([int(rs), 11])
return epos
Expand Down Expand Up @@ -85,7 +85,7 @@ def get_pairs(epos):
m2 : float-array
second of the mass-to-charge pairs,
with multiplicity>1.
dx,dy: x y detector coordinates
dx,dy: x y detector coordinates
"""
Expand All @@ -112,7 +112,7 @@ def get_pairs(epos):

def corr_his(m1, m2, nbins):
"""
creates a histogram based on the mass-to-charge values m1 and m2, and number of bins
creates a histogram based on the mass-to-charge values m1 and m2, and number of bins
Parameters
----------
m1 : float
Expand Down
File renamed without changes.
File renamed without changes.
78 changes: 58 additions & 20 deletions correlationHistogramAnalysis/dissociation_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
def parse_formula(formula):
"""Works for formulas of form AxBy where x,y=1 do not have to be mentioned otherwise x,y <=9"""
elements = {}
for char, nxtchar, nxt2char in zip(formula, formula[1:] + formula[:1], formula[2:] + formula[:2]):
for char, nxtchar, nxt2char in zip(
formula, formula[1:] + formula[:1], formula[2:] + formula[:2]
):
if char.isalpha() & char.isupper():
if nxtchar.isalpha() & nxtchar.islower():
if nxt2char.isnumeric():
Expand All @@ -25,7 +27,9 @@ def parse_formula(formula):
else:
elements[char] = int(nxtchar)
prime_list = [2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 31, 37, 41, 43, 47]
elements_prime = dict([(y, prime_list[x]) for x, y in enumerate(sorted(set(elements)))])
elements_prime = dict(
[(y, prime_list[x]) for x, y in enumerate(sorted(set(elements)))]
)
return elements, elements_prime


Expand Down Expand Up @@ -59,7 +63,11 @@ def generate_triple_products(elements):
for j in range(1, len(temp)):
second_product = temp[:j]
third_product = temp[j:]
trip = (tuple(sorted(first_product)), tuple(sorted(second_product)), tuple(sorted(third_product)))
trip = (
tuple(sorted(first_product)),
tuple(sorted(second_product)),
tuple(sorted(third_product)),
)
triplet = tuple(sorted(trip)) # Sort the elements to ensure uniqueness
if triplet not in triplets:
triplets.add(triplet)
Expand All @@ -76,12 +84,12 @@ def product_reparser(p1):
else:
product.append(key + str(p1[key]))

product = ''.join(product)
product = "".join(product)
return product


def possible_product_pairs(complex_formula, charge):
""" Based on the chemical formula, product pairs are generated efficiently."""
"""Based on the chemical formula, product pairs are generated efficiently."""
original_dict, _ = parse_formula(complex_formula)

def szudzik_pairing(a, b):
Expand All @@ -106,28 +114,45 @@ def generate_recursive_pairs(current_pair, remaining_values, remaining_keys):
pair1 = {key: i}
pair2 = {key: value - i}
new_pair = {**current_pair, **pair1}
pairs.extend(generate_recursive_pairs(new_pair, remaining_values, remaining_keys))
pairs.extend(
generate_recursive_pairs(new_pair, remaining_values, remaining_keys)
)
new_pair = {**current_pair, **pair2}
pairs.extend(generate_recursive_pairs(new_pair, remaining_values, remaining_keys))
pairs.extend(
generate_recursive_pairs(new_pair, remaining_values, remaining_keys)
)

return pairs

all_pairs = generate_recursive_pairs({}, values, keys)
unique_permutations = [dict(y) for y in set(tuple(x.items()) for x in all_pairs)]
unique_permutations = [
dict(y) for y in set(tuple(x.items()) for x in all_pairs)
]
return unique_permutations

unique_perms = generate_pairs(original_dict)
daughter_1 = {}
daughter_2 = {}
count = 0
prime_list = [2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 31, 37, 41, 43, 47]
elements_prime = dict([(y, prime_list[x]) for x, y in enumerate(sorted(set(list(original_dict.keys()))))])
elements_prime = dict(
[
(y, prime_list[x])
for x, y in enumerate(sorted(set(list(original_dict.keys()))))
]
)

for i in range(len(unique_perms)):
if all(value == 0 for value in unique_perms[i].values()) or unique_perms[i] == original_dict:
if (
all(value == 0 for value in unique_perms[i].values())
or unique_perms[i] == original_dict
):
continue
daughter_1[count] = unique_perms[i]
daughter_2[count] = {key: original_dict[key] - unique_perms[i][key] for key in original_dict.keys()}
daughter_2[count] = {
key: original_dict[key] - unique_perms[i][key]
for key in original_dict.keys()
}
count += 1

sp = []
Expand Down Expand Up @@ -186,14 +211,21 @@ def possible_product_triplets(complex_formula, charge):
return product_trip_1, product_trip_2, product_trip_3, ccp


def associate_mass(elements_mass, complex_formula=None, parent_charge=None, product_1=None, product_2=None,
charge_states=None, react_dict=None):
def associate_mass(
elements_mass,
complex_formula=None,
parent_charge=None,
product_1=None,
product_2=None,
charge_states=None,
react_dict=None,
):
if react_dict is not None:
complex_formula = react_dict['parent']
parent_charge = react_dict['cp']
product_1, _ = parse_formula(react_dict['daughter_1'])
product_2, _ = parse_formula(react_dict['daughter_2'])
charge_states = [react_dict['cd1'], react_dict['cd2']]
complex_formula = react_dict["parent"]
parent_charge = react_dict["cp"]
product_1, _ = parse_formula(react_dict["daughter_1"])
product_2, _ = parse_formula(react_dict["daughter_2"])
charge_states = [react_dict["cd1"], react_dict["cd2"]]
mp = 0
ss, _ = parse_formula(complex_formula)
for key, value in ss.items():
Expand Down Expand Up @@ -221,8 +253,14 @@ def digitize_track(m1e, m2e, m1d, m2d, h):
def index_values_in_bin(m1, m2, ind, m1e, m2e, bins_along_track):
indices_in_bin = []
for i in range(len(bins_along_track)):
indices_m1 = np.where((m1[ind] >= m1e[bins_along_track[i, 0]]) & (m1[ind] < m1e[bins_along_track[i, 0] + 1]))[0]
indices_m2 = np.where((m2[ind] >= m2e[bins_along_track[i, 1]]) & (m2[ind] < m2e[bins_along_track[i, 1] + 1]))[0]
indices_m1 = np.where(
(m1[ind] >= m1e[bins_along_track[i, 0]])
& (m1[ind] < m1e[bins_along_track[i, 0] + 1])
)[0]
indices_m2 = np.where(
(m2[ind] >= m2e[bins_along_track[i, 1]])
& (m2[ind] < m2e[bins_along_track[i, 1] + 1])
)[0]
if len(np.intersect1d(indices_m1, indices_m2)) != 0:
indices_in_bin.append(np.intersect1d(indices_m1, indices_m2))
indices_in_bin = np.concatenate(indices_in_bin)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed data/.DS_Store
Binary file not shown.
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "correlationHistogramAnalysis"
version = "0.2.1"
authors = [
{ name="Shyam Katnagallu", email="[email protected]" },
]
description = "A package for correlation histogram analysis in APT"
readme = "README.md"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
Homepage = "https://github.com/skatnagallu/CorrelationHistogram"
Issues = "https://github.com/skatnagallu/CorrelationHistogram/issues"

16 changes: 0 additions & 16 deletions setup.py

This file was deleted.

0 comments on commit 9688951

Please sign in to comment.