In order to solve lack of accurate protection relay models for power system dynamic simulation and being unable to accurately reflect protection action characteristics, a general modeling method of protection relay based on virtual relay is proposed. Virtual relay is a kind of simulation for real relay and it is defined with specific rules of logic operation. With hierarchical structure and object-oriented modeling strategy, this method has the advantages of clean logic and convenient modeling. An open and transparent protection relay model library is developed and dynamic simulation calculation including protection relay models is realized. It's easy for users to modify models and expand its functions. The simulation results show that the dynamic simulation program including protection relay models can more accurately reflect dynamic performance of electric power system after disturbance. It can be used to analyze cascading failures caused by incorrect action of protection relays, replay the accident in a long time after a disturbance in power system, and study the essence cause of accident and find the correct anti-fault measures.