Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.mol = Molecule('L2PdAr+I')
self.ipmol = IPMolecule(
'L2PdAr+I',
ipmethod='multiplicative',
dropmethod='threshold',
threshold=0.01,
)
def __iadd__(self, other):
if type(other) is str:
other = composition_from_formula(other)
elif isinstance(other, Molecule) is True:
other = other.composition
elif type(other) == dict:
pass
else:
raise ValueError(f'Addition of {other} to {self} is invalid')
new = copy.copy(self._comp) # starter for new dictionary
for key in other:
try:
new[key] += other[key]
except KeyError:
new[key] = other[key]
self.composition = new
return self
sys.stdout.write(f'{self}\n')
sys.stdout.write(f'formula: {self.molecular_formula}\n')
sys.stdout.write(f'molecular weight: {round(self.molecular_weight, 6)}\n')
sys.stdout.write(f'monoisotopic mass: {round(self.monoisotopic_mass, 6)}\n')
sys.stdout.write('\n')
self.print_percent_composition()
def print_percent_composition(self):
"""prints the percent composition in a reader-friendly format"""
sys.stdout.write('elemental percent composition:\n')
pcomp = self.percent_composition
for element, percent in sorted(pcomp.items()):
sys.stdout.write(f'{element}: {percent * 100.:6.4}%\n')
class IPMolecule(Molecule):
_ipmethod = None
_gausip = None # gaussian isotope pattern storage
_dropmethod = None
def __init__(self,
string: (str, dict),
charge=1,
consolidate=3,
criticalerror=3 * 10 ** -6,
decpl=7,
dropmethod=None,
emptyspec=True,
groupmethod='weighted',
ipmethod='hybrid',
keepall=False,
npeaks=5000,