def test_dict_conversion(self): m1 = Material([(Element('Mo'), 1.0), (Element('Fe'), 2.0), (Element('O'), 3.2)], dens=5.24, ID=13) m1.export(xray_units='sld') m1.export(xray_units='n_db') m1.export(xray_units='edens') with self.assertRaises(ValueError): m1.export(xray_units='test') m2 = Material('B[10]4C', dens=2.55) m2.export()
def calc_api(args): if 'protein' in args: try: material = collect_protein(args['protein']) except Exception as e: return repr(e) else: name = args.get('name', default='protein') elif 'dna' in args: try: material = collect_dna(args['dna']) except Exception as e: return repr(e) else: name = args.get('name', default='DNA') elif 'rna' in args: try: material = collect_rna(args['rna']) except Exception as e: return repr(e) else: name = args.get('name', default='RNA') elif 'formula' in args and 'density' in args: f = Formula(args['formula'], sort=False) try: material = Material(f, dens=float(args['density'])) except Exception as e: return repr(e) else: name = args.get('name', default='User Query') else: return 'Could not calculate, missing formula and density or protein/dna/rna sequence' material.name = name if args.get('material_description', default='') != '': material.extra_data['description'] = args['material_description'] out = material.export(xray_units=args.get('xray_unit', 'edens')) return json.dumps(out, indent=' ')