class Design:
    """ The Design class represents the whole schematic, which is also
    the top level of the output format.  The internal structure of this
    class closely matches the JSON output."""
    def __init__(self):
        self.nets = list()
        self.components = Components()
        self.component_instances = list()
        self.design_attributes = DesignAttributes()
        self.version = dict()
        self.set_version("0.1.0", "Upverter converter")

    def bounds(self):
        """ Return the min and max point of a design """
        bounds = [net.bounds() for net in self.nets]
        offset_bounds = lambda (x1, y1, x2, y2), (xo, yo): (x1 + xo, y1 + yo,
                                                            x2 + xo, y2 + yo)
        for comp in self.component_instances:
            offsets = [(att.x, att.y) for att in comp.symbol_attributes]
            lib_comp = self.components.components[comp.library_id]
            bbounds = [
                b.bounds() for b in lib_comp.symbols[comp.symbol_index].bodies
            ]
            bounds.extend(
                [offset_bounds(b, o) for b, o in zip(bbounds, offsets)])
            xs = sum([list(b[0::2]) for b in bounds], [])
            ys = sum([list(b[1::2]) for b in bounds], [])
        return [Point(min(xs), min(ys)), Point(max(xs), max(ys))]

    def set_version(self, file_version, exporter):
        """ Set the file version and exporter """
        self.version['file_version'] = file_version
        self.version['exporter'] = exporter

    def add_component_instance(self, component_instance):
        """ Add an instance """
        self.component_instances.append(component_instance)

    def add_component(self, library_id, component):
        """ Add a library part """
        self.components.add_component(library_id, component)

    def add_net(self, net):
        """ Add a net """
        self.nets.append(net)

    def set_design_attributes(self, design_attributes):
        """ Add design level attributes """
        self.design_attributes = design_attributes

    def json(self):
        """ Return a design as JSON """
        return {
            "version": self.version,
            "nets": [n.json() for n in self.nets],
            "components": self.components.json(),
            "component_instances":
            [i.json() for i in self.component_instances],
            "design_attributes": self.design_attributes.json()
        }
class Design:
    """ The Design class represents the whole schematic, which is also
    the top level of the output format.  The internal structure of this
    class closely matches the JSON output."""

    def __init__(self):
        self.nets = list()
        self.components = Components()
        self.component_instances = list()
        self.design_attributes = DesignAttributes()
        self.version = dict()
        self.set_version("0.0.1","Upverter converter")


    def set_version(self, file_version, exporter):
        self.version['file_version'] = file_version
        self.version['exporter'] = exporter


    def add_component_instance(self, component_instance):
        self.component_instances.append(component_instance)


    def add_component(self, library_id, component):
        self.components.add_component(library_id,component)


    def add_net(self, net):
        self.nets.append(net)


    def set_design_attributes(self, design_attributes):
        self.design_attributes = design_attributes


    def json(self):
        return {
            "version" : self.version,
            "nets" : [n.json() for n in self.nets],
            "components" : self.components.json(),
            "component_instances" :
                [i.json() for i in self.component_instances],
            "design_attributes" : self.design_attributes.json()
            }
Example #3
0
    try:
        entries = mpr.get_entries_in_chemsys(comp)
    except:
        continue
    if len(entries) == 0:
        continue
#    pd = PhaseDiagram(entries)
#    data = collections.defaultdict(list)
    for e in entries:
        com = e.entry_id
        prop = mpr.query(criteria={"task_id": com}, properties=[\
        "formation_energy_per_atom", \
        "energy_per_atom", \
        "spacegroup", \
        "pretty_formula", \
        "cif"])

        form_energy = prop[0]['formation_energy_per_atom']
        energy = prop[0]['energy_per_atom']
        sp = prop[0]['spacegroup']['symbol']
        name = prop[0]['pretty_formula']
        struct = prop[0]['cif']
        cif_name = './structure/' + com + '_' + name + '.cif'
        Comps.add_component(name, energy, sp, struct, cif_name)

        fcif = open(cif_name, 'w')
        fcif.write(struct)
        fcif.close()
Comps.get_formation_energy()
Comps.print_info()
class Design:
    """ The Design class represents the whole schematic, which is also
    the top level of the output format.  The internal structure of this
    class closely matches the JSON output."""

    def __init__(self):
        self.nets = list()
        self.components = Components()
        self.component_instances = list()
        self.design_attributes = DesignAttributes()
        self.version = dict()
        self.set_version("0.1.0","Upverter converter")


    def bounds(self):
        """ Return the min and max point of a design """
        bounds = [net.bounds() for net in self.nets]
        offset_bounds = lambda (x1, y1, x2, y2), (xo, yo): (x1+xo, y1+yo,
                                                            x2+xo, y2+yo)
        for comp in self.component_instances:
            offsets = [(att.x, att.y) for att in comp.symbol_attributes]
            lib_comp = self.components.components[comp.library_id]
            bbounds = [b.bounds() for b in
                       lib_comp.symbols[comp.symbol_index].bodies]
            bounds.extend([offset_bounds(b, o) for b, o in zip(bbounds, offsets)])
            xs = sum([list(b[0::2]) for b in bounds], [])
            ys = sum([list(b[1::2]) for b in bounds], [])
        return [Point(min(xs), min(ys)), Point(max(xs), max(ys))]


    def set_version(self, file_version, exporter):
        """ Set the file version and exporter """
        self.version['file_version'] = file_version
        self.version['exporter'] = exporter


    def add_component_instance(self, component_instance):
        """ Add an instance """
        self.component_instances.append(component_instance)


    def add_component(self, library_id, component):
        """ Add a library part """
        self.components.add_component(library_id, component)


    def add_net(self, net):
        """ Add a net """
        self.nets.append(net)


    def set_design_attributes(self, design_attributes):
        """ Add design level attributes """
        self.design_attributes = design_attributes


    def json(self):
        """ Return a design as JSON """
        return {
            "version" : self.version,
            "nets" : [n.json() for n in self.nets],
            "components" : self.components.json(),
            "component_instances" :
                [i.json() for i in self.component_instances],
            "design_attributes" : self.design_attributes.json()
            }