def load_specific_molecule(self, full_path): if re.match('.*\.json', full_path) is None: return "Path must contain a json file" else: json_file = open(full_path, "r") json_dict = eval(json_file.read()) json_file.close() id_map = {} molecule = NAOActorMolecule(self.memory, self.memory.atoms, self.nao_mem, self.nao_motion, duplication=True) atoms = json_dict["atoms"] molecular_graph = json_dict["molecular_graph"] for json_atom in atoms: new_atom = load_json_atom(json_atom, memory, nao_memory=self.nao_mem, nao_motion=self.nao_motion) self.memory.add_atom(new_atom, new_atom.get_id()) molecule.molecular_graph = json_graph.loads(molecular_graph) molecule.set_connections() memory.add_molecule(molecule) return molecule
def load_brain_archive(self): largest_atom_id = 0 last_atom_id = 0 base = "brain_archive/{0}/".format(config.robot_system) if not os.path.exists(base): os.makedirs(base) files = [o for o in os.listdir(base) if re.match('.*\.json', o)] for f in files: print f json_file = open("{0}{1}".format(base, f), "r") json_dict = eval(json_file.read()) json_file.close() id_map = {} molecule = NAOActorMolecule(self.memory, self.memory.atoms, self.nao_mem, self.nao_motion, duplication=True) atoms = json_dict["atoms"] molecular_graph = json_dict["molecular_graph"] for json_atom in atoms: new_atom = load_json_atom(json_atom, memory, nao_memory=self.nao_mem, nao_motion=self.nao_motion) atom_id_number = int( re.match('a-([0-9]+)', new_atom.id).group(1)) # print atom_id_number # print molecular_graph new_id = new_atom.create_id(atom_id_number + last_atom_id) molecular_graph = molecular_graph.replace(new_atom.id, new_id) # print molecular_graph atom_id_number += last_atom_id if atom_id_number > largest_atom_id: largest_atom_id = atom_id_number self.memory.add_atom(new_atom, new_id) print molecular_graph molecule.molecular_graph = json_graph.loads(molecular_graph) print molecule.molecular_graph molecule.set_connections() memory.add_molecule(molecule) memory.add_to_brain_archive(molecule) last_atom_id = largest_atom_id for molecule in self.memory.brain_archive: print molecule for a in molecule.get_atoms_as_list(): print a.print_atom() print "brain_archive:", self.memory.brain_archive
def load_specific_molecule(self,full_path): if re.match('.*\.json',full_path) is None: return "Path must contain a json file" else: json_file = open(full_path,"r") json_dict = eval(json_file.read()) json_file.close() id_map = {} molecule = EpuckActorMolecule(self.memory,self.memory.atoms,self.controller,duplication=True) atoms = json_dict["atoms"] molecular_graph = json_dict["molecular_graph"] for json_atom in atoms: new_atom = load_json_atom(json_atom,memory,epuck_controller=self.controller) self.memory.add_atom(new_atom,new_atom.get_id()) molecule.molecular_graph=json_graph.loads(molecular_graph) molecule.set_connections() memory.add_molecule(molecule) return molecule
def load_brain_archive(self): largest_atom_id = 0 last_atom_id = 0 base = "brain_archive/{0}/".format(config.robot_system) if not os.path.exists(base): os.makedirs(base) files = [o for o in os.listdir(base) if re.match('.*\.json',o)] for f in files: print f json_file = open("{0}{1}".format(base,f),"r") json_dict = eval(json_file.read()) json_file.close() id_map = {} molecule = NAOActorMolecule(self.memory,self.memory.atoms,self.nao_mem,self.nao_motion,duplication=True) atoms = json_dict["atoms"] molecular_graph = json_dict["molecular_graph"] for json_atom in atoms: new_atom = load_json_atom(json_atom,memory,nao_memory=self.nao_mem,nao_motion=self.nao_motion) atom_id_number = int(re.match('a-([0-9]+)',new_atom.id).group(1)) # print atom_id_number # print molecular_graph new_id = new_atom.create_id(atom_id_number + last_atom_id) molecular_graph = molecular_graph.replace( new_atom.id, new_id) # print molecular_graph atom_id_number += last_atom_id if atom_id_number > largest_atom_id: largest_atom_id = atom_id_number self.memory.add_atom(new_atom,new_id) print molecular_graph molecule.molecular_graph=json_graph.loads(molecular_graph) print molecule.molecular_graph molecule.set_connections() memory.add_molecule(molecule) memory.add_to_brain_archive(molecule) last_atom_id = largest_atom_id for molecule in self.memory.brain_archive: print molecule for a in molecule.get_atoms_as_list(): print a.print_atom() print "brain_archive:",self.memory.brain_archive