@@ -59,7 +59,7 @@ def load(self):
59
59
self .tree = tree
60
60
61
61
# MS version info
62
- root = tree .getroot ()
62
+ root = self . root = tree .getroot ()
63
63
ms_version = root .get ('Version' )
64
64
if ms_version :
65
65
self .ms_version = ms_version
@@ -107,7 +107,9 @@ def __get_identity_mappings(self):
107
107
108
108
if not identity_mappings :
109
109
msg = 'No IdentityMapping tag found.'
110
- raise ValueError (msg )
110
+ self .__logger .warning (msg )
111
+ return
112
+ #raise ValueError(msg)
111
113
112
114
return identity_mappings
113
115
@@ -125,58 +127,60 @@ def get_atom_info(self):
125
127
126
128
identity_mappings = self .__get_identity_mappings ()
127
129
128
- # For each IdentityMapping tag.
129
- for identity_mapping in identity_mappings :
130
-
131
- # For each Atom3d tag in IdentityMapping.
132
- for elem in identity_mapping .iter ('Atom3d' ):
133
- # Atom name and number
134
- atom = elem .attrib ['Components' ]
135
- atom_components .append (atom )
136
- if atom not in natoms_dict :
137
- natoms_dict .setdefault (atom , 1 )
138
- atom_types .append (atom )
139
- else :
140
- natoms_dict [atom ] += 1
141
-
142
- # Coordinates
143
- # NOTE: In bulk the origin point may not have coordinate,
144
- # so use '0.0,0.0,0.0' as default value.
145
- if 'XYZ' not in elem .attrib :
146
- xyz = '0.0,0.0,0.0'
147
- msg = ("Found an Atom3d tag without 'XYZ' attribute" +
148
- ", set to {}" ).format (xyz )
149
- self .__logger .info (msg )
150
- else :
151
- xyz = elem .attrib ['XYZ' ]
152
-
153
- coordinate = [float (i .strip ()) for i in xyz .split (',' )]
154
- if atom not in atomco_dict :
155
- atomco_dict .setdefault (atom , [coordinate ])
156
- else :
157
- atomco_dict [atom ].append (coordinate )
158
-
159
- # T&F info
160
- if 'RestrictedProperties' in elem .attrib :
161
- tf_info = ['F' , 'F' , 'F' ]
162
- else :
163
- tf_info = ['T' , 'T' , 'T' ]
164
- if atom not in tf_dict :
165
- tf_dict .setdefault (atom , [tf_info ])
166
- else :
167
- tf_dict [atom ].append (tf_info )
168
-
169
- # atom name
170
- atom_name = elem .attrib .get ('Name' )
171
- # Damn, sometimes tag has no Name attr,
172
- # so customize it
173
- # 有可能个别原子是从其他文件复制过来的原因
174
- if not atom_name :
175
- atom_name = atom + '_custom'
176
- if atom not in atom_name_dict :
177
- atom_name_dict .setdefault (atom , [atom_name ])
178
- else :
179
- atom_name_dict [atom ].append (atom_name )
130
+ if identity_mappings is None :
131
+ atom3d_iter = self .root .findall ('.//Atom3d' )
132
+ else :
133
+ atom3d_iter = identity_mappings [0 ].iter ('Atom3d' )
134
+
135
+ # For each Atom3d tag
136
+ for elem in atom3d_iter :
137
+ # Atom name and number
138
+ atom = elem .attrib ['Components' ]
139
+ atom_components .append (atom )
140
+ if atom not in natoms_dict :
141
+ natoms_dict .setdefault (atom , 1 )
142
+ atom_types .append (atom )
143
+ else :
144
+ natoms_dict [atom ] += 1
145
+
146
+ # Coordinates
147
+ # NOTE: In bulk the origin point may not have coordinate,
148
+ # so use '0.0,0.0,0.0' as default value.
149
+ if 'XYZ' not in elem .attrib :
150
+ xyz = '0.0,0.0,0.0'
151
+ msg = ("Found an Atom3d tag without 'XYZ' attribute" +
152
+ ", set to {}" ).format (xyz )
153
+ self .__logger .info (msg )
154
+ else :
155
+ xyz = elem .attrib ['XYZ' ]
156
+
157
+ coordinate = [float (i .strip ()) for i in xyz .split (',' )]
158
+ if atom not in atomco_dict :
159
+ atomco_dict .setdefault (atom , [coordinate ])
160
+ else :
161
+ atomco_dict [atom ].append (coordinate )
162
+
163
+ # T&F info
164
+ if 'RestrictedProperties' in elem .attrib :
165
+ tf_info = ['F' , 'F' , 'F' ]
166
+ else :
167
+ tf_info = ['T' , 'T' , 'T' ]
168
+ if atom not in tf_dict :
169
+ tf_dict .setdefault (atom , [tf_info ])
170
+ else :
171
+ tf_dict [atom ].append (tf_info )
172
+
173
+ # atom name
174
+ atom_name = elem .attrib .get ('Name' )
175
+ # Damn, sometimes tag has no Name attr,
176
+ # so customize it
177
+ # 有可能个别原子是从其他文件复制过来的原因
178
+ if not atom_name :
179
+ atom_name = atom + '_custom'
180
+ if atom not in atom_name_dict :
181
+ atom_name_dict .setdefault (atom , [atom_name ])
182
+ else :
183
+ atom_name_dict [atom ].append (atom_name )
180
184
181
185
atom_numbers = [natoms_dict [atm ] for atm in atom_types ]
182
186
@@ -204,11 +208,12 @@ def get_name_info(self):
204
208
获取文件中能量,力等数据.
205
209
"""
206
210
# Get info string.
211
+ info = None
207
212
for elem in self .tree .iter ("SymmetrySystem" ):
208
213
info = elem .attrib .get ('Name' )
209
- if info is None :
210
- return
211
214
break
215
+ if info is None :
216
+ return
212
217
213
218
# Get thermo data.
214
219
fieldnames = ["energy" , "force" , "magnetism" , "path" ]
0 commit comments