def test_merge_all_uvvis_2(self): uvvis1 = UvvisSpectrum(peaks=[UvvisPeak(value='345')]) uvvis2 = UvvisSpectrum(peaks=[UvvisPeak(value='123')]) comp = Compound(uvvis_spectra=[uvvis1, uvvis2]) gold = Compound(uvvis_spectra=[ UvvisSpectrum( peaks=[UvvisPeak(value='345'), UvvisPeak(value='123')]) ]) self.assertEqual(indep.merge_all_uvvis(comp), gold)
def test_is_unidentified(self): """Test is_unidentified method returns expected result.""" self.assertEqual(Compound().is_unidentified, True) self.assertEqual( Compound(names=['Coumarin 343']).is_unidentified, False) self.assertEqual(Compound(labels=['3a']).is_unidentified, False) self.assertEqual( Compound(names=['Coumarin 343'], labels=['3a']).is_unidentified, False) self.assertEqual( Compound(melting_points=[MeltingPoint( value='250')]).is_unidentified, True)
def test_is_contextual(self): """Test is_contextual method returns expected result.""" self.assertEqual(Compound(names=['Coumarin 343']).is_contextual, False) self.assertEqual( Compound(melting_points=[MeltingPoint(value='240')]).is_contextual, False) self.assertEqual( Compound(melting_points=[MeltingPoint(units='K')]).is_contextual, True) self.assertEqual( Compound(melting_points=[MeltingPoint( apparatus='Some apparatus')]).is_contextual, True) self.assertEqual( Compound(labels=['3a'], melting_points=[MeltingPoint(apparatus='Some apparatus') ]).is_contextual, False) self.assertEqual( Compound(uvvis_spectra=[UvvisSpectrum( apparatus='Some apparatus')]).is_contextual, True) self.assertEqual( Compound( uvvis_spectra=[UvvisSpectrum(peaks=[UvvisPeak( value='378')])]).is_contextual, False) self.assertEqual( Compound( uvvis_spectra=[UvvisSpectrum(peaks=[UvvisPeak( units='nm')])]).is_contextual, True)
def interpret(self, result, start, end): # print("inside cat cell") # print(etree.tostring(result)) # print() # print("test") c = Compound(catalyst_name=[CAT(name=first(result.xpath('text()')), )]) yield c
def interpret(self, result, start, end): context = {} # print("footnote temp") # print(etree.tostring(result)) # print() c = Compound() context = {} tempvalue = first(result.xpath('//value/text()')) tempunit = first(result.xpath('//units/text()')) if tempunit and '℃' in tempunit: tempunit = '°C' if not tempvalue and not tempunit: tempvalue = first(result.xpath('//tempphrase/text()')) # print(tempvalue) if not tempunit: if "K" in tempvalue: tempunit = 'K' tempvalue = tempvalue.strip('K') elif '°C' in tempvalue: tempunit = '°C' tempvalue = tempvalue.strip("°C") else: tempvalue = None context["tempvalue"] = tempvalue context["tempunits"] = tempunit if context: c.conv.append(Conv(**context)) yield c
def test_merge_uvvis_1(self): """Checks merge_peak_obj works in this context""" uvvis = UvvisSpectrum(peaks=[ UvvisPeak(value='123'), UvvisPeak(value='456'), UvvisPeak(extinction='35000'), UvvisPeak(extinction='40000') ]) comp = Compound(uvvis_spectra=[uvvis]) table_records = [] resolved_comp = indep.merge_uvvis(comp, table_records) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] }] } print(resolved_comp.serialize()) self.assertEqual(gold, resolved_comp.serialize())
def interpret(self, result, start, end): """""" compunits = [""] # print("inside comp header") # print(etree.tostring(result)) # print() if len(result) == 1: compunits = first(result.xpath('//unit/text()')) elif len(result) > 1: for item in result: compunit = first(item.xpath('//unit/text()')) if compunit: compunits[0] += compunit if compunits[0] == "": compunits = [] # print(flowunits) else: compunits = [] # print("comp header") if "/CO" in first( result.xpath('//compphrase/text()')) or ":CO" in first( result.xpath('//compphrase/text()')): compunits = first(result.xpath('//compphrase/text()')) if "CO/H2" in first( result.xpath('//compphrase/text()')) or "CO:H2" in first( result.xpath('//compphrase/text()')): compunits = first(result.xpath('//compphrase/text()')) # print(compunits) # print(compunits) c = Compound() if compunits: c.comp.append(Comp(unit=compunits)) yield c
def interpret(self, result, start, end): """""" context = {} c = Compound() no = first(result.xpath('./no/text()')) tempunits = first(result.xpath('./tempunits/text()')) context['tempunits'] = tempunits tempvalues = first(result.xpath('./tempvalue/text()')) context['tempvalue'] = tempvalues any = first(result.xpath('//any/text()')) context["convtype"] = any # print("inside conv heading") # print(etree.tostring(result)) check = result.xpath('/tempnumber') # print("check: ", check) # print() if check: # print("yes") c.conv.append(Conv(**{'check': "True"})) if no == None: context['convunits'] = first(result.xpath('./convunits/text()')) else: context['convunits'] = first(result.xpath('./no/text()')) if tempunits or any: c.conv.append(Conv(**context)) yield c
def interpret(self, result, start, end): # """""" # print("inside bet header") # print(etree.tostring(result)) # print() units = first(result.xpath('//units/text()')) # print(units) c = Compound(bet=[BET(unit=units)]) yield c
def test_get_indices(self): uvvis1 = UvvisSpectrum( peaks=[UvvisPeak( value='123'), UvvisPeak(value='456')]) uvvis2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis3 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) comp = Compound(uvvis_spectra=[uvvis1, uvvis2, uvvis3]) val, ext = indep.get_indices(comp) self.assertEqual(val, [0]) self.assertEqual(ext, [1, 2])
def interpret(self, result, start, end): compound = Compound( ff_pattern=[ Ff( value=first(result.xpath('./value/text()')), units=first(result.xpath('./units/text()')) ) ] ) yield compound
def interpret(self, result, start, end): compound = Compound( melting_points=[ MeltingPoint( value=first(result.xpath('./value/text()')), units=first(result.xpath('./units/text()')) ) ] ) yield compound
def interpret(self, result, start, end): pressure = first(result.xpath('//value/text()')) presunit = first(result.xpath('//units/text()')) if not pressure: pressure = first(result.xpath('//phrase/text()')) # print("inside cell of pres") # print(pressure) # print(presunit) c = Compound(conv=[Conv(pressure=pressure, pressureunit=presunit)]) yield c
def interpret(self, result, start, end): # print("inside cell") # print(etree.tostring(result)) # print() tofvalue = first(result.xpath('./tofvalue/text()')) tempvalue = first(result.xpath('./tempvalue/text()')) tempunits = first(result.xpath('./tempunits/text()')) c = Compound(conv=[ Conv(tofvalue=tofvalue, tempvalue=tempvalue, tempunits=tempunits) ]) yield c
def interpret(self, result, start, end): """""" # print("inside heading of pres") # print(etree.tostring(result)) presunits = first(result.xpath('//units/text()')) c = Compound() if presunits: c.conv.append(Conv(presunits=presunits)) yield c
def interpret(self, result, start, end): context = {} # print("footnote") # print(etree.tostring(result)) # print() c = Compound() catname = first(result.xpath('./cat_phrase/name/text()')) # print(catname) context["captioncatname"] = catname if context: c.conv.append(Conv(**context)) yield c
def interpret(self, result, start, end): # print("inside cell selectivity") # print(etree.tostring(result)) # print() value = result.xpath('./value/text()') sel = Selectivity(value=value) c = Compound() if value: c.conv.append(Conv(selectivity=[sel])) yield c
def test_merge_all_uvvis_1(self): peak1 = UvvisPeak(value='123', extinction='35000') peak2 = UvvisPeak(value='456', extinction='40000') comp = Compound(uvvis_spectra=[ UvvisSpectrum(peaks=[peak1]), UvvisSpectrum(peaks=[peak2]) ]) comp = indep.merge_all_uvvis(comp) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] }] } self.assertEqual(gold, comp.serialize())
def interpret(self, result, start, end): """""" # print("inside temp") # print(etree.tostring(result)) # print() # print(lollol) tempunits = first(result.xpath('./units/text()')) c = Compound() if tempunits: c.temp.append(Temp(unit=tempunits)) yield c
def interpret(self, result, start, end): # print("inside flow cell") # print(etree.tostring(result)) # print() c = Compound(flow=[ Flow( value=first(result.xpath('./value/text()')), unit=first(result.xpath('./units/text()')), ) ]) yield c
def test_merge_uvvis_3(self): """Checks check_prev works in this context""" uvvis_prev_1 = UvvisSpectrum(peaks=[UvvisPeak(value='123')]) uvvis_prev_2 = UvvisSpectrum(peaks=[UvvisPeak(value='456')]) uvvis_current_1 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis_current_2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) comp_prev = Compound(uvvis_spectra=[uvvis_prev_1, uvvis_prev_2]) comp_current = Compound( uvvis_spectra=[uvvis_current_1, uvvis_current_2]) table_records = [comp_prev] comp_current = indep.merge_uvvis(comp_current, table_records) gold_prev = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }] }, { 'peaks': [{ 'value': '456', 'extinction': '40000' }] }] } gold_current = {} self.assertEqual(gold_prev, comp_prev.serialize()) self.assertEqual(gold_current, comp_current.serialize())
def test_check_prev(self): uvvis_prev_1 = UvvisSpectrum(peaks=[UvvisPeak(value='123')]) uvvis_prev_2 = UvvisSpectrum(peaks=[UvvisPeak(value='456')]) uvvis_current_1 = UvvisSpectrum(peaks=[UvvisPeak(extinction='35000')]) uvvis_current_2 = UvvisSpectrum(peaks=[UvvisPeak(extinction='40000')]) comp_prev = Compound(uvvis_spectra=[uvvis_prev_1, uvvis_prev_2]) comp_current = Compound( uvvis_spectra=[uvvis_current_1, uvvis_current_2]) table_records = [comp_prev] comp_current = indep.check_prev(comp_current, [], [0, 1], table_records) gold_prev = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }] }, { 'peaks': [{ 'value': '456', 'extinction': '40000' }] }] } gold_current = {} self.assertEqual(gold_prev, comp_prev.serialize()) self.assertEqual(gold_current, comp_current.serialize())
def interpret(self, result, start, end): # print("inside betcell") # print(etree.tostring(result)) # print() value = result.xpath('//betvalue/text()') if len(value) < 1: value = result.xpath("//betcell/text()") units = first(result.xpath('//units/text()')) # # print(value) # print(units) c = Compound(bet=[BET(value=value, unit=units)]) yield c
def test_merge_uvvis_4(self): """Checks merge_all_uvvis works in this context""" peak1 = UvvisPeak(value='123', extinction='35000') peak2 = UvvisPeak(value='456', extinction='40000') comp = Compound(uvvis_spectra=[ UvvisSpectrum(peaks=[peak1]), UvvisSpectrum(peaks=[peak2]) ]) row_compound = [] comp = indep.merge_uvvis(comp, row_compound) gold = { 'uvvis_spectra': [{ 'peaks': [{ 'value': '123', 'extinction': '35000' }, { 'value': '456', 'extinction': '40000' }] }] } self.assertEqual(gold, comp.serialize())
def interpret(self, result, start, end): """""" # print("inside heading selectivity") # print(etree.tostring(result)) # print() selectivityunits = first(result.xpath('//units/text()')) # print(selectivityunits) # print() c = Compound() if selectivityunits: sel = Selectivity(unit=selectivityunits) c.conv.append(Conv(selectivity=[sel])) # print(c.serialize()) yield c
def interpret(self, result, start, end): # for item in result: # print("inside cell") # print(etree.tostring(item)) # print() convvalue = first(result.xpath('//convvalue/text()')) convunits = first(result.xpath('//convunits/text()')) tempvalue = first(result.xpath('//tempvalue/text()')) tempunits = first(result.xpath('//tempunits/text()')) c = Compound(conv=[ Conv(convvalue=convvalue, convunits=convunits, tempvalue=tempvalue, tempunits=tempunits) ]) yield c
def interpret(self, result, start, end): """""" # print("inside flow header") # print(etree.tostring(result)) # print() if type(result) == type([]): for i in result: flowunits = first(i.xpath('//unit/text()')) if flowunits != None: break else: flowunits = first(result.xpath('//unit/text()')) c = Compound() if flowunits: c.flow.append(Flow(unit=flowunits)) yield c
def interpret(self, result, start, end): c = Compound() s = Anneal() tempunits = first(result.xpath('./tempunits/text()')) timeunits = first(result.xpath('./timeunits/text()')) for temp in result.xpath('./temps/temp'): anneal_temp = AnnealTemp(tempvalue=first( temp.xpath('./tempvalue/text()')), tempunits=tempunits) s.temps.append(anneal_temp) for time in result.xpath('./times/time'): anneal_time = AnnealTime(timevalue=first( time.xpath('./timevalue/text()')), timeunits=timeunits) s.times.append(anneal_time) c.anneal.append(s) yield c
def interpret(self, result, start, end): # print("inside heading of tof") # print(etree.tostring(result)) context = {} no = first(result.xpath('./no/text()')) context['tempunits'] = first(result.xpath('./tempunits/text()')) context['tempvalue'] = first(result.xpath('./tempvalue/text()')) if no == None: context['convunits'] = first(result.xpath('./convunits/text()')) else: context['convunits'] = first(result.xpath('./no/text()')) c = Compound() if tempunits: c.conv.append(Conv(**context)) yield c
def interpret(self, result, start, end): c = Compound() s = SpinCoat( # solvent=first(result.xpath('./solvent/text()')) ) spdunits = first(result.xpath('./spdunits/text()')) timeunits = first(result.xpath('./timeunits/text()')) for spd in result.xpath('./spds/spd'): spin_spd = SpinSpd(spdvalue=first(spd.xpath('./spdvalue/text()')), spdunits=spdunits) s.spds.append(spin_spd) for time in result.xpath('./times/time'): spin_time = SpinTime(timevalue=first( time.xpath('./timevalue/text()')), timeunits=timeunits) s.times.append(spin_time) c.spin_coat.append(s) yield c