Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #199 from schwancr/libyaml
Browse files Browse the repository at this point in the history
Added functionality to use CLoader / CDumper from yaml
  • Loading branch information
rmcgibbo committed May 24, 2013
2 parents 238f9cc + beb21bf commit 0125d58
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/python/project/project.py
Expand Up @@ -19,6 +19,15 @@
import os
import numpy as np
import yaml
# if CLoader/CDumper are available (i.e. user has libyaml installed)
# then use them since they are much faster.
try:
from yaml import CLoader as Loader
from yaml import CDumper as Dumper
except ImportError:
from yaml import Loader
from yaml import Dumper

from msmbuilder import Trajectory
from msmbuilder import io
from msmbuilder import MSMLib
Expand Down Expand Up @@ -141,7 +150,7 @@ def load_from(cls, filename):

if filename.endswith('.yaml'):
with open(filename) as f:
ondisk = yaml.load(f)
ondisk = yaml.load(f, Loader=Loader)
records = {'conf_filename': ondisk['conf_filename'],
'traj_lengths': [],
'traj_paths': [],
Expand Down Expand Up @@ -212,7 +221,7 @@ def save(self, filename_or_file):
'length': int(self._traj_lengths[i]),
'errors': self._traj_errors[i]})

yaml.dump(records, handle)
yaml.dump(records, handle, Dumper=Dumper)

if own_fid:
handle.close()
Expand Down

0 comments on commit 0125d58

Please sign in to comment.