# -*- coding: utf-8 -*-

import json

from maxwellbloch import ob_base, field

class OBAtom(ob_base.OBBase):

    def __init__(self, num_states=0, energies=[], decays=[], fields=[]):

        self.num_states = num_states
        self.energies = energies
        self.decays = decays

        self.build_fields(fields)

    def __repr__(self):
        return ("Atom(num_states={0}, " +
                "energies={1}, " +
                "decays={2}, " +
                "fields={3})").format(self.num_states,
                                    self.energies,
                                    self.decays,
                                    self.fields)

    def add_field(self, field_dict):
        self.fields.append(field.Field(**field_dict))

    def build_fields(self, field_dicts):
        self.fields = []
        for f in field_dicts:
            self.add_field(f)
        return self.fields

    def get_json_dict(self):

        json_dict = { "num_states": self.num_states,
                      "energies": self.energies,
                      "decays": self.decays,
                      "fields": [f.__dict__ for f in self.fields] }
        return json_dict

    def to_json_str(self):
        """ Return a JSON string representation of the Atom object.

        Returns:
            (string) JSON representation of the Atom object.
        """

        return json.dumps(self.get_json_dict())

    def to_json(self, file_path):

        with open(file_path, 'w') as fp:
            json.dump(self.get_json_dict(), fp=fp, indent=2, separators=None, 
                      sort_keys=True)

    @classmethod
    def from_json_str(cls, json_str):
        json_dict = json.loads(json_str)
        return cls(**json_dict)

    @classmethod
    def from_json(cls, file_path):
        with open(file_path) as json_file:
            json_dict = json.load(json_file)
        return cls(**json_dict)

def main():

    print(OBAtom())

if __name__ == '__main__':
    status = main()
@@ -304,32 +304,100 @@
 fields(fields)%0A%0A
+        self.build_H_0(energies)%0A        self.build_c_ops(decays)%0A%0A%0A
     def __repr__
@@ -965,16 +965,1312 @@
 fields%0A%0A
+    def build_H_0(self, energies=%5B%5D): %0A        %22%22%22 Takes a list of energies and makes a Bare Hamiltonian with the%0A        energies as diagonals.%0A%0A        Leave the list empty for all zero energies (i.e. if you don't care%0A        about absolute energies.)%0A%0A        Args:%0A            energies: list of pre-interaction energies%0A%0A        Returns:%0A            H_0 = %5Benergies%5B0%5D             0  ...%5D%0A                  %5B             0 energies%5B1%5D ...%5D%0A                  %5B           ...         ... ...%5D%0A%0A        %22%22%22%0A%0A        if energies:%0A            H_0 = np.diag(np.array(energies))%0A        else:%0A            H_0 = np.zeros(%5Bself.num_states, self.num_states%5D)%0A%0A        self.H_0 = qu.Qobj(H_0)%0A        return self.H_0%0A%0A    def build_c_ops(self, decays=%5B%5D):%0A        %22%22%22 Takes a list of spontaneous decay rates and makes a list of%0A        collapse operators to be passed to the solver.%0A%0A        Args: %0A            decays: list of dicts representing decays.%0A            e.g.%0A            %5B %7B %22rate%22: 1.0, %22channels%22: %5B%5B0,1%5D%5D %7D%0A              %7B %22rate%22: 2.0, %22channels%22: %5B%5B2,1%5D, %5B3,1%5D%5D %7D %5D%0A        %22%22%22%0A%0A        self.c_ops = %5B%5D%0A%0A        for d in decays:%0A            r = d%5B%22rate%22%5D%0A            for c in d%5B%22channels%22%5D:%0A                self.c_ops.append(np.sqrt(r)*self.sigma(c%5B0%5D,c%5B1%5D))%0A        return self.c_ops%0A%0A
     def 

Add H_0 and c_ops to OBAtom