3131 + 0.5 * \sum_{p,q,r,s} h[p,q,r,s] a_p^\dagger a_q^\dagger a_r a_s
3232"""
3333
34- # Define a compatible basestring for checking between Python 2 and 3
35- try :
36- basestring
37- except NameError : # pragma: no cover
38- basestring = str
39-
4034
4135# Define error objects which inherit from Exception.
4236class MoleculeNameError (Exception ):
@@ -248,7 +242,7 @@ def name_molecule(geometry, basis, multiplicity, charge, description):
248242 Raises:
249243 MoleculeNameError: If spin multiplicity is not valid.
250244 """
251- if not isinstance (geometry , basestring ):
245+ if not isinstance (geometry , str ):
252246 # Get sorted atom vector.
253247 atoms = [item [0 ] for item in geometry ]
254248 atom_charge_info = [(atom , atoms .count (atom )) for atom in set (atoms )]
@@ -501,7 +495,7 @@ def __init__(
501495
502496 # Metadata fields with default values.
503497 self .charge = charge
504- if not isinstance (description , basestring ):
498+ if not isinstance (description , str ):
505499 raise TypeError ("description must be a string." )
506500 self .description = description
507501
@@ -518,7 +512,7 @@ def __init__(
518512 self .filename = data_directory + '/' + self .name
519513
520514 # Attributes generated automatically by class.
521- if not isinstance (geometry , basestring ):
515+ if not isinstance (geometry , str ):
522516 self .n_atoms = len (geometry )
523517 self .atoms = sorted (
524518 [row [0 ] for row in geometry ], key = lambda atom : periodic_hash_table [atom ]
@@ -707,7 +701,7 @@ def save(self):
707701 with h5py .File ("{}.hdf5" .format (tmp_name ), "w" ) as f :
708702 # Save geometry (atoms and positions need to be separate):
709703 d_geom = f .create_group ("geometry" )
710- if not isinstance (self .geometry , basestring ):
704+ if not isinstance (self .geometry , str ):
711705 atoms = [numpy .bytes_ (item [0 ]) for item in self .geometry ]
712706 positions = numpy .array ([list (item [1 ]) for item in self .geometry ])
713707 else :
0 commit comments