From 1065ff310172fad1f2cfb79dda7ea737de2cdab1 Mon Sep 17 00:00:00 2001 From: Peter Boyd Date: Thu, 12 Dec 2019 20:49:54 -0500 Subject: [PATCH] fixing a few legacy networkx commands. Fixes #28 --- lammps_interface/lammps_main.py | 10 +++++----- lammps_interface/structure_data.py | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lammps_interface/lammps_main.py b/lammps_interface/lammps_main.py index 978726b..ae8c2c2 100755 --- a/lammps_interface/lammps_main.py +++ b/lammps_interface/lammps_main.py @@ -101,13 +101,13 @@ def unique_atoms(self, g): if data['force_field_type'] is None: if data['h_bond_donor']: # add neighbors to signify type of hbond donor - label = (data['element'], data['h_bond_donor'], molid, tuple(sorted([g.node[j]['element'] for j in g.neighbors(node)]))) + label = (data['element'], data['h_bond_donor'], molid, tuple(sorted([g.nodes[j]['element'] for j in g.neighbors(node)]))) else: label = (data['element'], data['h_bond_donor'], molid) else: if data['h_bond_donor']: # add neighbors to signify type of hbond donor - label = (data['force_field_type'], data['h_bond_donor'], molid, tuple(sorted([g.node[j]['element'] for j in g.neighbors(node)]))) + label = (data['force_field_type'], data['h_bond_donor'], molid, tuple(sorted([g.nodes[j]['element'] for j in g.neighbors(node)]))) else: label = (data['force_field_type'], data['h_bond_donor'], molid) @@ -447,7 +447,7 @@ def assign_force_fields(self): # prompt for ForceField? rep = self.subgraphs[self.molecule_types[mtype][0]] #response = input("Would you like to apply a new force field to molecule type %i with atoms (%s)? [y/n]: "% - # (mtype, ", ".join([rep.node[j]['element'] for j in rep.nodes()]))) + # (mtype, ", ".join([rep.nodes[j]['element'] for j in rep.nodes()]))) #ff = self.options.force_field #if response.lower() in ['y','yes']: # ff = input("Please enter the name of the force field: ") @@ -459,7 +459,7 @@ def assign_force_fields(self): ff = self.options.mol_ff if ff is None: ff = self.options.force_field - atoms = ", ".join([rep.node[j]['element'] for j in rep.nodes()]) + atoms = ", ".join([rep.nodes[j]['element'] for j in rep.nodes()]) print("WARNING: Molecule %s with atoms (%s) will be using the %s force field as no "%(mtype,atoms,ff)+ " value was set for molecules. To prevent this warning "+ "set --molecule-ff=[some force field] on the command line.") @@ -531,7 +531,7 @@ def compute_simulation_size(self): # prompt for replication of this molecule in the supercell. rep = self.subgraphs[self.molecule_types[mtype][0]] response = input("Would you like to replicate molceule %i with atoms (%s) in the supercell? [y/n]: "% - (mtype, ", ".join([rep.node[j]['element'] for j in rep.nodes()]))) + (mtype, ", ".join([rep.nodes[j]['element'] for j in rep.nodes()]))) if response in ['y', 'Y', 'yes']: for m in self.molecule_types[mtype]: self.subgraphs[m].build_supercell(supercell, self.cell, track_molecule=True, molecule_len=molcount) diff --git a/lammps_interface/structure_data.py b/lammps_interface/structure_data.py index 6e3d4fc..3e865f7 100644 --- a/lammps_interface/structure_data.py +++ b/lammps_interface/structure_data.py @@ -1162,7 +1162,7 @@ def detect_clusters(self, num_neighbors, tol, type='Inorganic', general_metal=Fa # found cluster # update the 'hybridization' data for i,j in clique: - self.nodes[i]['special_flag'] = cluster.node[j]['special_flag'] + self.nodes[i]['special_flag'] = cluster.nodes[j]['special_flag'] cluster_found = True print("Found %s"%(name)) store_sbus.setdefault(name, []).append([i for (i,j) in clique]) @@ -1281,13 +1281,13 @@ def build_supercell(self, sc, lattice, track_molecule=False, molecule_len=0, red # keep track of original index value from the unit cell. for i in range(1, totatomlen+1): - graph_image.node[unit_node_ids[i-1]+offset]['image'] = unit_node_ids[i-1] + graph_image.nodes[unit_node_ids[i-1]+offset]['image'] = unit_node_ids[i-1] if track_molecule: self.molecule_images.append(graph_image.nodes()) graph_image.molecule_id = orig_copy.molecule_id + mol_offset # update cartesian coordinates for each node in the image for node in graph_image.nodes(): - data = graph_image.node[node] + data = graph_image.nodes[node] n_orig = data['image'] if track_molecule: data['molid'] = graph_image.molecule_id @@ -1353,8 +1353,8 @@ def build_supercell(self, sc, lattice, track_molecule=False, molecule_len=0, red n1,n2 = graph_image.sorted_edge_dict[(v1,v2)] # flag boundary crossings, and determine updated nodes. # check symmetry flags if they need to be updated, - n1_data = graph_image.node[n1] - n2_data = graph_image.node[n2] + n1_data = graph_image.nodes[n1] + n2_data = graph_image.nodes[n2] try: n1_orig = n1_data['image'] n2_orig = n2_data['image'] @@ -1454,7 +1454,7 @@ def build_supercell(self, sc, lattice, track_molecule=False, molecule_len=0, red union_graphs.append(graph_image) for G in union_graphs: for node in G.nodes(): - data = G.node[node] + data = G.nodes[node] self.add_node(node, **data) #once nodes are added, add edges. for G in union_graphs: @@ -1649,8 +1649,8 @@ def write_CIF(graph, cell): sym = data['symflag'] - label1 = "%s%i"%(graph.node[n1]['element'], n1) - label2 = "%s%i"%(graph.node[n2]['element'], n2) + label1 = "%s%i"%(graph.nodes[n1]['element'], n1) + label2 = "%s%i"%(graph.nodes[n2]['element'], n2) c.add_data("bonds", _geom_bond_atom_site_label_1= CIF.geom_bond_atom_site_label_1(label1)) c.add_data("bonds", _geom_bond_atom_site_label_2= @@ -1831,8 +1831,8 @@ def write_RASPA_CIF(graph, cell,classifier=0): # sym = data['symflag'] - # label1 = "%s%i"%(graph.node[n1]['element'], n1) - # label2 = "%s%i"%(graph.node[n2]['element'], n2) + # label1 = "%s%i"%(graph.nodes[n1]['element'], n1) + # label2 = "%s%i"%(graph.nodes[n2]['element'], n2) # c.add_data("bonds", _geom_bond_atom_site_label_1= # CIF.geom_bond_atom_site_label_1(label1)) # c.add_data("bonds", _geom_bond_atom_site_label_2= @@ -1879,7 +1879,7 @@ def write_RASPA_sim_files(lammps_sim,classifier=0): if(int(data['image']) > max_image): max_image = int(data['image']) - #keys.append(lammps_sim.graph.node[n]['force_field_type']) + #keys.append(lammps_sim.graph.nodes[n]['force_field_type']) elif(classifier == 1): for node, data in sorted(lammps_sim.graph.nodes_iter2(data=True)): @@ -1890,7 +1890,7 @@ def write_RASPA_sim_files(lammps_sim,classifier=0): if(int(data['image']) > max_image): max_image = int(data['image']) - #keys.append(lammps_sim.graph.node[n]['force_field_type']) + #keys.append(lammps_sim.graph.nodes[n]['force_field_type']) print(max_image) for i in range(len(data_list)):