Developing heteroatom-rich porous carbon (HPC) for electricity storage promotes the use of green sustainable energy. To efficiently prepare and optimize HPC, it is necessary to explore its formation/doping mechanism. Here, HPCs are prepared from nontoxic organic crystals, and quantum chemical calculations and ReaxFF MD simulations are performed. Effects of carbon chains and functional groups on HPCs are investigated. In micromorphology, the open-chain compound changes little and is etched into interconnected particles. The compounds containing ring chains change a lot and form 2D thin layers. The dimer forms 3D flower-like structures composed of thin layers. During doping, N in the amino group has a tendency to form pyrrolic-N, and N in the N-heterocycle has a tendency to form quaternary-N. L-lysine-derived HPC shows a large specific surface area (3353.99 m 2 g −1 ). For symmetric supercapacitor, it possesses high specific capacitance (439.11 F g −1 at 0.3 A g −1 and 265.57 F g −1 at 100 A g −1 ) and high cyclic stability (maintained 96.86% after 5000 cycles). For asymmetric supercapacitor, it shows more pseudocapacitance (accounted for 33.84% at 20 mV s −1 ) and higher specific capacitance (586.58 F g −1 at 0.3 A g −1 and 457.40 F g −1 at 100 A g −1 ). In gel electrolyte, its power density and energy density increase by 39.58% and 133.21%, respectively, with voltage rising from 1 V to 1.4 V. The results provide theoretical guidance and high-performance HPCs for clean energy storage/conversion.