def test1(): datadir = resource_filename('sknano', 'data') dirnames, fnames = listdir(datadir) assert_true('__init__.py' in fnames) assert_true('fullerenes' in dirnames) assert_equal(dirnames, listdir_dirnames(datadir)) assert_equal(fnames, listdir_fnames(datadir))
def analyze_structure(rootdir=None, structure_file=None, **kwargs): if rootdir is None or not os.path.isdir(rootdir): rootdir = os.curdir rundirs = \ listdir_dirnames(rootdir, filterfunc=lambda name: name.startswith('run_')) ion_coordination_counter = Counter() graphene_coordination_counter = Counter() for rundir in rundirs: dumpdata = StructureReader.read(os.path.join(rundir, structure_file)) dumpdata.remap_atomattr_names({'c_atom_ke': 'ke'}) trj = dumpdata.trajectory final_snapshot = trj[-1] atoms = final_snapshot.atoms atoms.mapatomattr('type', 'element', {1: 'C', 2: 'N'}) atoms.update_attrs() ion = atoms.filtered(atoms.elements == 'N')[0] graphene = atoms.filtered(atoms.elements == 'C') ion_coordination_counter.update([ion.CN]) graphene_coordination_counter.update(graphene.coordination_numbers) statstr = 'run statistics:\n' statstr += 'rundir: {}\n'.format(rundir) statstr += 'ion CN: {}\n'.format(ion.CN) statstr += 'graphene CN counts: {}\n'.format( Counter(graphene.coordination_numbers)) print(statstr) print('final stats') print('ion_coordination_counter: {}'.format(ion_coordination_counter)) print('graphene_coordination_counter: {}'.format( graphene_coordination_counter))
def load_fullerene_data(): """Helper function to populate dict of fullerene data files.""" datadir = resource_filename('sknano', 'data/fullerenes') fullerenes = \ listdir_dirnames(datadir, filterfunc=lambda name: name.startswith('C')) fullerene_data = {} for fullerene in fullerenes: datapath = os.path.join('data', 'fullerenes', fullerene) datadir = resource_filename('sknano', datapath) fullerene_data[fullerene] = listdir_fnames(datadir) return fullerene_data
def test2(): datadir = resource_filename('sknano', 'data') filterfunc = lambda name: '_' not in name dirnames, fnames = listdir(datadir, filterfunc=filterfunc, filter_fnames=True, filter_dirnames=True) assert_true('__pycache__' not in dirnames) assert_true('__init__.py' not in fnames) assert_equal(dirnames, listdir_dirnames(datadir, filterfunc=filterfunc)) assert_equal(fnames, listdir_fnames(datadir, filterfunc=filterfunc))